creates the update_file method in repository.rb and applies changes accordingly

This commit is contained in:
tiagonbotelho 2016-07-04 11:32:57 +01:00
parent 385afc28ef
commit 9951854648
5 changed files with 35 additions and 3 deletions

View File

@ -8,7 +8,8 @@ module CreatesCommit
source_project: @project,
source_branch: @ref,
target_branch: @target_branch,
file_path: @path
file_path: @path,
previous_path: @previous_path
)
result = service.new(@tree_edit_project, current_user, commit_params).execute

View File

@ -44,7 +44,7 @@ class Projects::BlobController < Projects::ApplicationController
"#file-path-#{hexdigest(@path)}"
else
unless params[:file_name] == @path
previous_path = @path
@previous_path = @path
@path = params[:file_name]
end
namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path))

View File

@ -731,6 +731,36 @@ class Repository
end
end
def update_file(user, path, previous_path, content, message, branch, update)
commit_with_hooks(user, branch) do |ref|
committer = user_to_committer(user)
options = {}
options[:committer] = committer
options[:author] = committer
options[:commit] = {
message: message,
branch: ref,
}
if previous_path
options[:file] = {
path: previous_path
}
Gitlab::Git::Blob.remove(raw_repository, options)
end
options[:file] = {
content: content,
path: path,
update: update
}
Gitlab::Git::Blob.commit(raw_repository, options)
end
end
def remove_file(user, path, message, branch)
commit_with_hooks(user, branch) do |ref|
committer = user_to_committer(user)

View File

@ -9,6 +9,7 @@ module Files
@commit_message = params[:commit_message]
@file_path = params[:file_path]
@previous_path = params[:previous_path]
@file_content = if params[:file_content_encoding] == 'base64'
Base64.decode64(params[:file_content])
else

View File

@ -4,7 +4,7 @@ module Files
class UpdateService < Files::BaseService
def commit
# Need to update file_path with the new filename
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch, true)
repository.update_file(current_user, @file_path, @previous_path, @file_content, @commit_message, @target_branch, true)
end
end
end