Commit b26abe8ff8c22241c78024089926f63a17e7d86b
1 parent
60959df3
Exists in
master
and in
4 other branches
Delete file action for satellites
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
1 changed file
with
43 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
| 1 | +require_relative 'file_action' | ||
| 2 | + | ||
| 3 | +module Gitlab | ||
| 4 | + module Satellite | ||
| 5 | + class DeleteFileAction < FileAction | ||
| 6 | + # Deletes file and creates a new commit for it | ||
| 7 | + # | ||
| 8 | + # Returns false if committing the change fails | ||
| 9 | + # Returns false if pushing from the satellite to bare repo failed or was rejected | ||
| 10 | + # Returns true otherwise | ||
| 11 | + def commit!(content, commit_message) | ||
| 12 | + in_locked_and_timed_satellite do |repo| | ||
| 13 | + prepare_satellite!(repo) | ||
| 14 | + | ||
| 15 | + # create target branch in satellite at the corresponding commit from bare repo | ||
| 16 | + repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}") | ||
| 17 | + | ||
| 18 | + # update the file in the satellite's working dir | ||
| 19 | + file_path_in_satellite = File.join(repo.working_dir, file_path) | ||
| 20 | + File.delete(file_path_in_satellite) | ||
| 21 | + | ||
| 22 | + # add removed file | ||
| 23 | + repo.add(file_path_in_satellite) | ||
| 24 | + | ||
| 25 | + # commit the changes | ||
| 26 | + # will raise CommandFailed when commit fails | ||
| 27 | + repo.git.commit(raise: true, timeout: true, a: true, m: commit_message) | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + # push commit back to bare repo | ||
| 31 | + # will raise CommandFailed when push fails | ||
| 32 | + repo.git.push({raise: true, timeout: true}, :origin, ref) | ||
| 33 | + | ||
| 34 | + # everything worked | ||
| 35 | + true | ||
| 36 | + end | ||
| 37 | + rescue Grit::Git::CommandFailed => ex | ||
| 38 | + Gitlab::GitLogger.error(ex.message) | ||
| 39 | + false | ||
| 40 | + end | ||
| 41 | + end | ||
| 42 | + end | ||
| 43 | +end |