summaryrefslogtreecommitdiff
path: root/app/models/snippet_repository.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-29 12:08:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-29 12:08:19 +0000
commitbae24262df90b1b16e012360d04a28d54a07be3f (patch)
treeab1dc4eba454832b1514d074de1e4a79624ad2c3 /app/models/snippet_repository.rb
parent589c0d68c188079dd5fd463e70d0c93631086998 (diff)
downloadgitlab-ce-bae24262df90b1b16e012360d04a28d54a07be3f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/snippet_repository.rb')
-rw-r--r--app/models/snippet_repository.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/app/models/snippet_repository.rb b/app/models/snippet_repository.rb
index 2276851b7a1..8151308125a 100644
--- a/app/models/snippet_repository.rb
+++ b/app/models/snippet_repository.rb
@@ -53,10 +53,21 @@ class SnippetRepository < ApplicationRecord
def transform_file_entries(files)
next_index = get_last_empty_file_index + 1
- files.each do |file_entry|
+ files.map do |file_entry|
file_entry[:file_path] = file_path_for(file_entry, next_index) { next_index += 1 }
file_entry[:action] = infer_action(file_entry) unless file_entry[:action]
- end
+ file_entry[:action] = file_entry[:action].to_sym
+
+ if only_rename_action?(file_entry)
+ file_entry[:infer_content] = true
+ elsif empty_update_action?(file_entry)
+ # There is no need to perform a repository operation
+ # When the update action has no content
+ file_entry = nil
+ end
+
+ file_entry
+ end.compact
end
def file_path_for(file_entry, next_index)
@@ -111,4 +122,12 @@ class SnippetRepository < ApplicationRecord
err.is_a?(ArgumentError) &&
err.message.downcase.match?(/failed to parse signature/)
end
+
+ def only_rename_action?(action)
+ action[:action] == :move && action[:content].nil?
+ end
+
+ def empty_update_action?(action)
+ action[:action] == :update && action[:content].nil?
+ end
end