summaryrefslogtreecommitdiff
path: root/app/services/files
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-11-27 16:27:51 +0000
committerNick Thomas <nick@gitlab.com>2018-11-28 11:50:05 +0000
commit14076062df5d9f369c42796e754b3918965a0623 (patch)
tree6f3e1a36914178a879002a2872d8e1e114652a1c /app/services/files
parenta54352406ae4d85a8c3352b4f6a7dfe669ecd817 (diff)
downloadgitlab-ce-14076062df5d9f369c42796e754b3918965a0623.tar.gz
Commits API: Preserve file content in move operations if unspecified
Diffstat (limited to 'app/services/files')
-rw-r--r--app/services/files/multi_service.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb
index c9d3ee31d82..927634c2159 100644
--- a/app/services/files/multi_service.rb
+++ b/app/services/files/multi_service.rb
@@ -8,6 +8,7 @@ module Files
transformer = Lfs::FileTransformer.new(project, @branch_name)
actions = actions_after_lfs_transformation(transformer, params[:actions])
+ actions = transform_move_actions(actions)
commit_actions!(actions)
end
@@ -26,6 +27,16 @@ module Files
end
end
+ # When moving a file, `content: nil` means "use the contents of the previous
+ # file", while `content: ''` means "move the file and set it to empty"
+ def transform_move_actions(actions)
+ actions.map do |action|
+ action[:infer_content] = true if action[:content].nil?
+
+ action
+ end
+ end
+
def commit_actions!(actions)
repository.multi_action(
current_user,