lib/gitlab_git/blob.rb in gitlab_git-10.2.3 vs lib/gitlab_git/blob.rb in gitlab_git-10.3.0
- old
+ new
@@ -148,11 +148,17 @@
end
if action == :remove
index.remove(filename)
else
- mode = 0100644
+ if action == :rename
+ old_path_name = PathHelper.normalize_path(file[:previous_path])
+ old_filename = old_path_name.to_s
+ index.remove(old_filename)
+ end
+
+ mode = 0o100644
file_entry = index.get(filename)
if file_entry
raise Repository::InvalidBlobName.new("Filename already exists; update not allowed") unless update
# Preserve the current file mode if one is available
@@ -204,9 +210,38 @@
# branch: 'master'
# }
#
def remove(repository, options)
commit(repository, options, :remove)
+ end
+
+
+ # Rename file from repository and return commit sha
+ #
+ # options should contain next structure:
+ # file: {
+ # previous_path: 'documents/old_story.txt'
+ # path: 'documents/story.txt'
+ # content: 'Lorem ipsum...',
+ # update: true
+ # },
+ # author: {
+ # email: 'user@example.com',
+ # name: 'Test User',
+ # time: Time.now
+ # },
+ # committer: {
+ # email: 'user@example.com',
+ # name: 'Test User',
+ # time: Time.now
+ # },
+ # commit: {
+ # message: 'Rename FILENAME',
+ # branch: 'master'
+ # }
+ #
+ def rename(repository, options)
+ commit(repository, options, :rename)
end
end
def initialize(options)
%w(id name path size data mode commit_id).each do |key|