diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 25 | ||||
-rw-r--r-- | app/services/files/create_service.rb | 24 | ||||
-rw-r--r-- | app/services/files/update_service.rb | 24 |
5 files changed, 62 insertions, 17 deletions
@@ -45,7 +45,7 @@ gem "browser" # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 7.1.13' +gem "gitlab_git", '~> 7.2.0' # Ruby/Rack Git Smart-HTTP Server Handler # GitLab fork with a lot of changes (improved thread-safety, better memory usage etc) diff --git a/Gemfile.lock b/Gemfile.lock index cc373f5a0d7..3d21dff2990 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -225,7 +225,7 @@ GEM mime-types (~> 1.19) gitlab_emoji (0.1.0) gemojione (~> 2.0) - gitlab_git (7.1.13) + gitlab_git (7.2.0) activesupport (~> 4.0) charlock_holmes (~> 0.6) gitlab-linguist (~> 3.0) @@ -733,7 +733,7 @@ DEPENDENCIES gitlab-grack (~> 2.0.2) gitlab-linguist (~> 3.0.1) gitlab_emoji (~> 0.1) - gitlab_git (~> 7.1.13) + gitlab_git (~> 7.2.0) gitlab_meta (= 7.0) gitlab_omniauth-ldap (= 1.2.1) gollum-lib (~> 4.0.2) diff --git a/app/models/repository.rb b/app/models/repository.rb index 1b8c74028d9..c5580503281 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -370,6 +370,31 @@ class Repository @root_ref ||= raw_repository.root_ref end + def commit_file(user, path, content, message, ref) + path[0] = '' if path[0] == '/' + + author = { + email: user.email, + name: user.name, + time: Time.now + } + + options = {} + options[:committer] = author + options[:author] = author + options[:commit] = { + message: message, + branch: ref + } + + options[:file] = { + content: content, + path: path + } + + Gitlab::Git::Blob.commit(raw_repository, options) + end + private def cache diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb index 23833aa78ec..c0cf5956326 100644 --- a/app/services/files/create_service.rb +++ b/app/services/files/create_service.rb @@ -33,14 +33,24 @@ module Files end end + if params[:encoding] == 'base64' + new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, file_path) + created_successfully = new_file_action.commit!( + params[:content], + params[:commit_message], + params[:encoding], + params[:new_branch] + ) + else + created_successfull = repository.commit_file( + current_user, + file_path, + params[:content], + params[:commit_message], + params[:new_branch] || ref + ) + end - new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, file_path) - created_successfully = new_file_action.commit!( - params[:content], - params[:commit_message], - params[:encoding], - params[:new_branch] - ) if created_successfully success diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 0724d3ae634..5efd43d16ce 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -19,13 +19,23 @@ module Files return error("You can only edit text files") end - edit_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) - edit_file_action.commit!( - params[:content], - params[:commit_message], - params[:encoding], - params[:new_branch] - ) + if params[:encoding] == 'base64' + edit_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) + edit_file_action.commit!( + params[:content], + params[:commit_message], + params[:encoding], + params[:new_branch] + ) + else + repository.commit_file( + current_user, + path, + params[:content], + params[:commit_message], + params[:new_branch] || ref + ) + end success rescue Gitlab::Satellite::CheckoutFailed => ex |