summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortiagonbotelho <tiagonbotelho@hotmail.com>2016-07-04 11:32:57 +0100
committertiagonbotelho <tiagonbotelho@hotmail.com>2016-07-04 11:32:57 +0100
commit6b836637235a36e6fe3b6b4911064cc3421a231a (patch)
tree9f3bf39dc3a71ae6bfd0f9c8546707fb8de0a236
parentb95b23f3ed649fc58dc7dbd1ec3703d2d7f75187 (diff)
downloadgitlab-ce-6b836637235a36e6fe3b6b4911064cc3421a231a.tar.gz
creates the update_file method in repository.rb and applies changes accordingly
-rw-r--r--app/controllers/concerns/creates_commit.rb3
-rw-r--r--app/controllers/projects/blob_controller.rb2
-rw-r--r--app/models/repository.rb30
-rw-r--r--app/services/files/base_service.rb1
-rw-r--r--app/services/files/update_service.rb2
5 files changed, 35 insertions, 3 deletions
diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb
index 84b4a30c6d5..036805306f2 100644
--- a/app/controllers/concerns/creates_commit.rb
+++ b/app/controllers/concerns/creates_commit.rb
@@ -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
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index 2bd86a1f126..1e96f471483 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -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
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 078ca8f4e13..a5fb13eb662 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -741,6 +741,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)
diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb
index 0326a8823e9..29bd450bb98 100644
--- a/app/services/files/base_service.rb
+++ b/app/services/files/base_service.rb
@@ -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
diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb
index 52451d72b57..6d015642b91 100644
--- a/app/services/files/update_service.rb
+++ b/app/services/files/update_service.rb
@@ -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