diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-12-15 23:24:12 -0500 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2017-12-20 01:24:53 -0500 |
commit | c210ddab9289e29fadc9a5a0462ffbe864af736c (patch) | |
tree | f64ad586aba389319be6e07d14b117f0bf048761 /app | |
parent | 81331fa77e181d193f444c34443d6ef0c5b01ed6 (diff) | |
download | gitlab-ce-c210ddab9289e29fadc9a5a0462ffbe864af736c.tar.gz |
Check if file has been modified for each action provided.
When commiting multiple files we're now checking if any of those files
has been modified by another commit and we're rejecting the new commit
in this case.
Diffstat (limited to 'app')
-rw-r--r-- | app/services/files/multi_service.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb index bfacc462847..eb2773733b1 100644 --- a/app/services/files/multi_service.rb +++ b/app/services/files/multi_service.rb @@ -20,6 +20,7 @@ module Files params[:actions].each do |action| validate_action!(action) + validate_file_status(action) end end @@ -28,5 +29,16 @@ module Files raise_error("Unknown action '#{action[:action]}'") end end + + def validate_file_status(action) + return unless action[:last_commit_id] + + current_commit = Gitlab::Git::Commit.last_for_path( + @start_project.repository, @start_branch, action[:file_path]) + + if current_commit.sha != action[:last_commit_id] + raise_error("The file has changed since you started editing it: #{action[:file_path]}") + end + end end end |