From 3bda96215845932ea6dea9e619a94dada1a61ade Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 16:32:56 +0100 Subject: implements the form for renaming the new filename on the file edit page --- app/controllers/projects/blob_controller.rb | 3 ++- app/services/files/update_service.rb | 1 + app/views/projects/blob/_editor.html.haml | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 7599fec3cdf..4c42be7d710 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,7 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path)) + # params[:file_name] stores the new name for the file + namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, params[:file_name])) end create_commit(Files::UpdateService, success_path: after_edit_path, diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 1960dc7d949..52451d72b57 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -3,6 +3,7 @@ require_relative "base_service" 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) end end diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml index 29c7d45074a..3c64b2f5e96 100644 --- a/app/views/projects/blob/_editor.html.haml +++ b/app/views/projects/blob/_editor.html.haml @@ -4,7 +4,11 @@ = icon('code-fork') = ref %span.editor-file-name - = @path + - if current_action?(:edit) && can?(current_user, :push_code, @project) + = text_field_tag 'file_name', params[:file_name], placeholder: @path, + class: 'form-control new-file-name' + - else + = @path - if current_action?(:new) || current_action?(:create) %span.editor-file-name -- cgit v1.2.1 From f4b38792a5c6f76b92350ef19ab53a351d01bdc4 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:46:37 +0100 Subject: successfully adds the new version with the updated name on the projects repo --- app/controllers/concerns/creates_commit.rb | 3 ++- app/controllers/projects/blob_controller.rb | 6 +++++- app/services/files/base_service.rb | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index dacb5679dd3..84b4a30c6d5 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -7,7 +7,8 @@ module CreatesCommit commit_params = @commit_params.merge( source_project: @project, source_branch: @ref, - target_branch: @target_branch + target_branch: @target_branch, + file_path: @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 4c42be7d710..e76d5009855 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -44,7 +44,11 @@ class Projects::BlobController < Projects::ApplicationController "#file-path-#{hexdigest(@path)}" else # params[:file_name] stores the new name for the file - namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, params[:file_name])) + unless params[:file_name] == @path + @path = params[:file_name] + end + + namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path)) end create_commit(Files::UpdateService, success_path: after_edit_path, diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index 0326a8823e9..cd5b45262ac 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,6 +15,8 @@ module Files params[:file_content] end + puts @file_path + # Validate parameters validate -- cgit v1.2.1 From 0ffdb567ce893f6957f06087950c35118d5b65f6 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:53:05 +0100 Subject: remove prints and useless comments --- app/controllers/projects/blob_controller.rb | 2 +- app/services/files/base_service.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index e76d5009855..2bd86a1f126 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,8 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - # params[:file_name] stores the new name for the file unless params[:file_name] == @path + previous_path = @path @path = params[:file_name] end diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index cd5b45262ac..0326a8823e9 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,8 +15,6 @@ module Files params[:file_content] end - puts @file_path - # Validate parameters validate -- cgit v1.2.1 From e2e588d2a8f6349208de92a8c0818d5a9178ab19 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 16:32:56 +0100 Subject: implements the form for renaming the new filename on the file edit page --- app/controllers/projects/blob_controller.rb | 3 ++- app/services/files/update_service.rb | 1 + app/views/projects/blob/_editor.html.haml | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 7599fec3cdf..4c42be7d710 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,7 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path)) + # params[:file_name] stores the new name for the file + namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, params[:file_name])) end create_commit(Files::UpdateService, success_path: after_edit_path, diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 1960dc7d949..52451d72b57 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -3,6 +3,7 @@ require_relative "base_service" 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) end end diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml index 29c7d45074a..3c64b2f5e96 100644 --- a/app/views/projects/blob/_editor.html.haml +++ b/app/views/projects/blob/_editor.html.haml @@ -4,7 +4,11 @@ = icon('code-fork') = ref %span.editor-file-name - = @path + - if current_action?(:edit) && can?(current_user, :push_code, @project) + = text_field_tag 'file_name', params[:file_name], placeholder: @path, + class: 'form-control new-file-name' + - else + = @path - if current_action?(:new) || current_action?(:create) %span.editor-file-name -- cgit v1.2.1 From ad799589866ee0aa18a66af2fff453daaf8d9457 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:46:37 +0100 Subject: successfully adds the new version with the updated name on the projects repo --- app/controllers/concerns/creates_commit.rb | 3 ++- app/controllers/projects/blob_controller.rb | 6 +++++- app/services/files/base_service.rb | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index dacb5679dd3..84b4a30c6d5 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -7,7 +7,8 @@ module CreatesCommit commit_params = @commit_params.merge( source_project: @project, source_branch: @ref, - target_branch: @target_branch + target_branch: @target_branch, + file_path: @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 4c42be7d710..e76d5009855 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -44,7 +44,11 @@ class Projects::BlobController < Projects::ApplicationController "#file-path-#{hexdigest(@path)}" else # params[:file_name] stores the new name for the file - namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, params[:file_name])) + unless params[:file_name] == @path + @path = params[:file_name] + end + + namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path)) end create_commit(Files::UpdateService, success_path: after_edit_path, diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index 0326a8823e9..cd5b45262ac 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,6 +15,8 @@ module Files params[:file_content] end + puts @file_path + # Validate parameters validate -- cgit v1.2.1 From b95b23f3ed649fc58dc7dbd1ec3703d2d7f75187 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:53:05 +0100 Subject: remove prints and useless comments --- app/controllers/projects/blob_controller.rb | 2 +- app/services/files/base_service.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index e76d5009855..2bd86a1f126 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,8 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - # params[:file_name] stores the new name for the file unless params[:file_name] == @path + previous_path = @path @path = params[:file_name] end diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index cd5b45262ac..0326a8823e9 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,8 +15,6 @@ module Files params[:file_content] end - puts @file_path - # Validate parameters validate -- cgit v1.2.1 From 6b836637235a36e6fe3b6b4911064cc3421a231a Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Mon, 4 Jul 2016 11:32:57 +0100 Subject: creates the update_file method in repository.rb and applies changes accordingly --- app/controllers/concerns/creates_commit.rb | 3 ++- app/controllers/projects/blob_controller.rb | 2 +- app/models/repository.rb | 30 +++++++++++++++++++++++++++++ app/services/files/base_service.rb | 1 + app/services/files/update_service.rb | 2 +- 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 -- cgit v1.2.1 From 85d1a9708ea31084147911243be248a02e89c56a Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 16:32:56 +0100 Subject: implements the form for renaming the new filename on the file edit page --- app/controllers/projects/blob_controller.rb | 3 ++- app/services/files/update_service.rb | 1 + app/views/projects/blob/_editor.html.haml | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 7599fec3cdf..4c42be7d710 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,7 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path)) + # params[:file_name] stores the new name for the file + namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, params[:file_name])) end create_commit(Files::UpdateService, success_path: after_edit_path, diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 1960dc7d949..52451d72b57 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -3,6 +3,7 @@ require_relative "base_service" 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) end end diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml index 29c7d45074a..3c64b2f5e96 100644 --- a/app/views/projects/blob/_editor.html.haml +++ b/app/views/projects/blob/_editor.html.haml @@ -4,7 +4,11 @@ = icon('code-fork') = ref %span.editor-file-name - = @path + - if current_action?(:edit) && can?(current_user, :push_code, @project) + = text_field_tag 'file_name', params[:file_name], placeholder: @path, + class: 'form-control new-file-name' + - else + = @path - if current_action?(:new) || current_action?(:create) %span.editor-file-name -- cgit v1.2.1 From dd161e155d7bb2632a522db1c89c352b8374cead Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:46:37 +0100 Subject: successfully adds the new version with the updated name on the projects repo --- app/controllers/concerns/creates_commit.rb | 3 ++- app/controllers/projects/blob_controller.rb | 6 +++++- app/services/files/base_service.rb | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index dacb5679dd3..84b4a30c6d5 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -7,7 +7,8 @@ module CreatesCommit commit_params = @commit_params.merge( source_project: @project, source_branch: @ref, - target_branch: @target_branch + target_branch: @target_branch, + file_path: @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 4c42be7d710..e76d5009855 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -44,7 +44,11 @@ class Projects::BlobController < Projects::ApplicationController "#file-path-#{hexdigest(@path)}" else # params[:file_name] stores the new name for the file - namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, params[:file_name])) + unless params[:file_name] == @path + @path = params[:file_name] + end + + namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @path)) end create_commit(Files::UpdateService, success_path: after_edit_path, diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index 0326a8823e9..cd5b45262ac 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,6 +15,8 @@ module Files params[:file_content] end + puts @file_path + # Validate parameters validate -- cgit v1.2.1 From 6b474d404627b20c86555586d56f0cc3b99845dd Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:53:05 +0100 Subject: remove prints and useless comments --- app/controllers/projects/blob_controller.rb | 2 +- app/services/files/base_service.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index e76d5009855..2bd86a1f126 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,8 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - # params[:file_name] stores the new name for the file unless params[:file_name] == @path + previous_path = @path @path = params[:file_name] end diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index cd5b45262ac..0326a8823e9 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,8 +15,6 @@ module Files params[:file_content] end - puts @file_path - # Validate parameters validate -- cgit v1.2.1 From 3e97068c64034a29bbf1e33948a56f67cf6635a1 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Mon, 4 Jul 2016 16:46:37 +0100 Subject: refactors blob_controller --- Gemfile | 2 +- Gemfile.lock | 17 +++++++++------ app/controllers/concerns/creates_commit.rb | 8 +++++++ app/controllers/projects/blob_controller.rb | 4 ++-- app/models/repository.rb | 33 +++++++++++++++++++++++++++++ app/services/files/update_service.rb | 5 ++++- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index e409e66aab0..0ba6bbdb4b1 100644 --- a/Gemfile +++ b/Gemfile @@ -52,7 +52,7 @@ gem "browser", '~> 2.2' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 10.2' +gem "gitlab_git", '~> 10.2', path: "~/src/Gitlab/gitlab_git" # LDAP Auth # GitLab fork with several improvements to original library. For full list of changes diff --git a/Gemfile.lock b/Gemfile.lock index 35c3770d42c..4e976370de4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +PATH + remote: ~/src/Gitlab/gitlab_git + specs: + gitlab_git (10.3.0) + activesupport (~> 4.0) + charlock_holmes (~> 0.7.3) + github-linguist (~> 4.7.0) + rugged (~> 0.24.0) + GEM remote: https://rubygems.org/ specs: @@ -276,11 +285,6 @@ GEM posix-spawn (~> 0.3) gitlab_emoji (0.3.1) gemojione (~> 2.2, >= 2.2.1) - gitlab_git (10.2.3) - activesupport (~> 4.0) - charlock_holmes (~> 0.7.3) - github-linguist (~> 4.7.0) - rugged (~> 0.24.0) gitlab_meta (7.0) gitlab_omniauth-ldap (1.2.1) net-ldap (~> 0.9) @@ -391,6 +395,7 @@ GEM mail_room (0.8.0) method_source (0.8.2) mime-types (2.99.2) + mime-types-data (3.2016.0521) mimemagic (0.3.0) mini_portile2 (2.1.0) minitest (5.7.0) @@ -863,7 +868,7 @@ DEPENDENCIES github-markup (~> 1.3.1) gitlab-flowdock-git-hook (~> 1.0.1) gitlab_emoji (~> 0.3.0) - gitlab_git (~> 10.2) + gitlab_git (~> 10.2)! gitlab_meta (= 7.0) gitlab_omniauth-ldap (~> 1.2.1) gollum-lib (~> 4.1.0) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index 84b4a30c6d5..dc157121106 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -11,8 +11,16 @@ module CreatesCommit file_path: @path ) + puts "#" * 10 + puts @previous_path + puts "#" * 10 + result = service.new(@tree_edit_project, current_user, commit_params).execute + puts "#" * 30 + puts result[:status] + puts "#" * 30 + if result[:status] == :success update_flash_notice(success_notice) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 2bd86a1f126..e2ddda1474b 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -43,8 +43,8 @@ class Projects::BlobController < Projects::ApplicationController diffs_namespace_project_merge_request_path(from_merge_request.target_project.namespace, from_merge_request.target_project, from_merge_request) + "#file-path-#{hexdigest(@path)}" else - unless params[:file_name] == @path - previous_path = @path + unless params[:file_name].empty? + @previous_path = @path @path = params[:file_name] end diff --git a/app/models/repository.rb b/app/models/repository.rb index 078ca8f4e13..75071c65efb 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -741,6 +741,39 @@ 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 + } + + options[:file] = { + content: content, + path: path, + update: update + } + + if previous_path + options[:file].merge!(previous_path: previous_path) + + puts "#" * 90 + puts "Hello" + puts "#" * 90 + Gitlab::Git::Blob.rename(raw_repository, options) + else + puts "#" * 90 + puts "World" + puts "#" * 90 + Gitlab::Git::Blob.commit(raw_repository, options) + end + 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/update_service.rb b/app/services/files/update_service.rb index 52451d72b57..7b7bce20662 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -4,7 +4,10 @@ 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) + puts "#" * 10 + puts @previous_path + puts "#" * 10 + repository.update_file(current_user, @file_path, @previous_path, @file_content, @commit_message, @target_branch, true) end end end -- cgit v1.2.1 From c5630fbf979dfe6b412d2deb8e98480d2c912a63 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:46:37 +0100 Subject: successfully adds the new version with the updated name on the projects repo --- app/services/files/base_service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index 0326a8823e9..cd5b45262ac 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,6 +15,8 @@ module Files params[:file_content] end + puts @file_path + # Validate parameters validate -- cgit v1.2.1 From 3824e8e1c4315bb3d1b2c1389f442d3b5e94f945 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 1 Jul 2016 17:53:05 +0100 Subject: remove prints and useless comments --- app/services/files/base_service.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index cd5b45262ac..0326a8823e9 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -15,8 +15,6 @@ module Files params[:file_content] end - puts @file_path - # Validate parameters validate -- cgit v1.2.1 From 08c15116d197ff1267e0cc1c1403af65e8b41772 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Mon, 4 Jul 2016 11:32:57 +0100 Subject: creates the update_file method in repository.rb and applies changes accordingly --- app/controllers/concerns/creates_commit.rb | 3 ++- app/models/repository.rb | 16 ++++++++++++++++ app/services/files/base_service.rb | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index dc157121106..a3731b45df0 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 ) puts "#" * 10 diff --git a/app/models/repository.rb b/app/models/repository.rb index 75071c65efb..37455e67328 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -749,15 +749,31 @@ class Repository options[:author] = committer options[:commit] = { message: message, +<<<<<<< 3824e8e1c4315bb3d1b2c1389f442d3b5e94f945 branch: ref } +======= + branch: ref, + } + + if previous_path + options[:file] = { + path: previous_path + } + + + Gitlab::Git::Blob.remove(raw_repository, options) + end + +>>>>>>> creates the update_file method in repository.rb and applies changes accordingly options[:file] = { content: content, path: path, update: update } +<<<<<<< 3824e8e1c4315bb3d1b2c1389f442d3b5e94f945 if previous_path options[:file].merge!(previous_path: previous_path) 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 -- cgit v1.2.1 From f30d2b7153e135b30135af06848ca4bfa20007bb Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Tue, 5 Jul 2016 09:46:48 +0100 Subject: removes debugging prints from code --- Gemfile | 2 +- Gemfile.lock | 7 ++++--- app/controllers/concerns/creates_commit.rb | 8 -------- app/models/repository.rb | 6 ------ app/services/files/update_service.rb | 3 --- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 0ba6bbdb4b1..5ea2c8c17e0 100644 --- a/Gemfile +++ b/Gemfile @@ -52,7 +52,7 @@ gem "browser", '~> 2.2' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 10.2', path: "~/src/Gitlab/gitlab_git" +gem "gitlab_git", '~> 10.2', git: "git@gitlab.com:gitlab-org/gitlab_git.git", branch: "commit-blob-rename-action" # LDAP Auth # GitLab fork with several improvements to original library. For full list of changes diff --git a/Gemfile.lock b/Gemfile.lock index 4e976370de4..6d9c9627202 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,7 @@ -PATH - remote: ~/src/Gitlab/gitlab_git +GIT + remote: git@gitlab.com:gitlab-org/gitlab_git.git + revision: 0e4ac299b806fa4190c4928a1c1ed5372fffbb38 + branch: commit-blob-rename-action specs: gitlab_git (10.3.0) activesupport (~> 4.0) @@ -395,7 +397,6 @@ GEM mail_room (0.8.0) method_source (0.8.2) mime-types (2.99.2) - mime-types-data (3.2016.0521) mimemagic (0.3.0) mini_portile2 (2.1.0) minitest (5.7.0) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index a3731b45df0..036805306f2 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -12,16 +12,8 @@ module CreatesCommit previous_path: @previous_path ) - puts "#" * 10 - puts @previous_path - puts "#" * 10 - result = service.new(@tree_edit_project, current_user, commit_params).execute - puts "#" * 30 - puts result[:status] - puts "#" * 30 - if result[:status] == :success update_flash_notice(success_notice) diff --git a/app/models/repository.rb b/app/models/repository.rb index 75071c65efb..bf45f48e61a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -761,14 +761,8 @@ class Repository if previous_path options[:file].merge!(previous_path: previous_path) - puts "#" * 90 - puts "Hello" - puts "#" * 90 Gitlab::Git::Blob.rename(raw_repository, options) else - puts "#" * 90 - puts "World" - puts "#" * 90 Gitlab::Git::Blob.commit(raw_repository, options) end end diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 7b7bce20662..6d015642b91 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -4,9 +4,6 @@ module Files class UpdateService < Files::BaseService def commit # Need to update file_path with the new filename - puts "#" * 10 - puts @previous_path - puts "#" * 10 repository.update_file(current_user, @file_path, @previous_path, @file_content, @commit_message, @target_branch, true) end end -- cgit v1.2.1 From a00d574ae921c2a9c1f694c1bf496d8ec28b9e23 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 11:07:16 +0100 Subject: adds change to CHANGELOG file --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 5b91ee1159c..2c54710be5d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.10.0 (unreleased) + - Add the functionality to be able to rename a file. !5049 (tiagonbotelho) - Fix commit builds API, return all builds for all pipelines for given commit. !4849 - Replace Haml with Hamlit to make view rendering faster. !3666 - Refactor repository paths handling to allow multiple git mount points -- cgit v1.2.1 From 0173b65d2605a6c332152fae2e53e84ba26a0df2 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 11:25:45 +0100 Subject: refactors to pass values as arguments through options --- app/models/repository.rb | 25 +++++++++++++------------ app/services/files/update_service.rb | 4 +++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index bf45f48e61a..38ef1b2c57b 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -741,29 +741,30 @@ class Repository end end - def update_file(user, path, previous_path, content, message, branch, update) + # previous_path, message, update + def update_file(user, path, content, branch, options={}) commit_with_hooks(user, branch) do |ref| committer = user_to_committer(user) - options = {} - options[:committer] = committer - options[:author] = committer - options[:commit] = { - message: message, + commit_options = {} + commit_options[:committer] = committer + commit_options[:author] = committer + commit_options[:commit] = { + message: options[:message], branch: ref } - options[:file] = { + commit_options[:file] = { content: content, path: path, - update: update + update: options[:update] } - if previous_path - options[:file].merge!(previous_path: previous_path) + if options[:previous_path] + commit_options[:file].merge!(previous_path: options[:previous_path]) - Gitlab::Git::Blob.rename(raw_repository, options) + Gitlab::Git::Blob.rename(raw_repository, commit_options) else - Gitlab::Git::Blob.commit(raw_repository, options) + Gitlab::Git::Blob.commit(raw_repository, commit_options) end end end diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 6d015642b91..7835d7eba44 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -4,7 +4,9 @@ module Files class UpdateService < Files::BaseService def commit # Need to update file_path with the new filename - repository.update_file(current_user, @file_path, @previous_path, @file_content, @commit_message, @target_branch, true) + repository.update_file(current_user, @file_path, @file_content, + @target_branch, previous_path: @previous_path, + message: @commit_message, update: true) end end end -- cgit v1.2.1 From c98369207917e83d445fe94a350a9fba7f17fd0c Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 11:28:50 +0100 Subject: removes redundant comment --- app/services/files/update_service.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index 7835d7eba44..905c7a7c81a 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -3,7 +3,6 @@ require_relative "base_service" module Files class UpdateService < Files::BaseService def commit - # Need to update file_path with the new filename repository.update_file(current_user, @file_path, @file_content, @target_branch, previous_path: @previous_path, message: @commit_message, update: true) -- cgit v1.2.1 From 8840dcf679bf40c70e2fb0f1d6823b8138d3fe20 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 13:51:28 +0100 Subject: fixes issues for mr acceptance --- app/models/repository.rb | 2 +- app/views/projects/blob/_editor.html.haml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 38ef1b2c57b..ea7355b3c08 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -760,7 +760,7 @@ class Repository } if options[:previous_path] - commit_options[:file].merge!(previous_path: options[:previous_path]) + commit_options[:file][:previous_path] = options[:previous_path] Gitlab::Git::Blob.rename(raw_repository, commit_options) else diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml index 3c64b2f5e96..31bd4646d3d 100644 --- a/app/views/projects/blob/_editor.html.haml +++ b/app/views/projects/blob/_editor.html.haml @@ -4,11 +4,9 @@ = icon('code-fork') = ref %span.editor-file-name - - if current_action?(:edit) && can?(current_user, :push_code, @project) - = text_field_tag 'file_name', params[:file_name], placeholder: @path, + -if current_action?(:edit) || current_action?(:update) + = text_field_tag 'file_name', (params[:file_name] or @path), class: 'form-control new-file-name' - - else - = @path - if current_action?(:new) || current_action?(:create) %span.editor-file-name -- cgit v1.2.1