From a30f278bdee399346f199ada0e33f5c2d233d861 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 6 Jan 2017 04:18:51 +0800 Subject: [PATCH] Fix for initial commit and remove unneeded args --- app/controllers/concerns/creates_commit.rb | 12 +++++++++--- app/services/commits/change_service.rb | 11 +++++++++-- lib/api/commits.rb | 2 -- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index eafaed8a3d0..f5f9cdeaec5 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -4,9 +4,10 @@ module CreatesCommit def create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil) set_commit_variables + source_branch = @mr_target_branch unless initial_commit? commit_params = @commit_params.merge( source_project: @mr_target_project, - source_branch: @mr_target_branch, + source_branch: source_branch, target_branch: @mr_source_branch ) @@ -113,7 +114,7 @@ module CreatesCommit else # Merge request to this project @mr_target_project = @project - @mr_target_branch ||= @ref + @mr_target_branch = @ref || @target_branch end else # Edit file in fork @@ -121,7 +122,12 @@ module CreatesCommit # Merge request from fork to this project @mr_source_project = @tree_edit_project @mr_target_project = @project - @mr_target_branch ||= @ref + @mr_target_branch = @ref || @target_branch end end + + def initial_commit? + @mr_target_branch.nil? || + !@mr_target_project.repository.branch_exists?(@mr_target_branch) + end end diff --git a/app/services/commits/change_service.rb b/app/services/commits/change_service.rb index 60bd59a5d9f..4a5d8029413 100644 --- a/app/services/commits/change_service.rb +++ b/app/services/commits/change_service.rb @@ -26,8 +26,15 @@ module Commits def commit_change(action) raise NotImplementedError unless repository.respond_to?(action) - into = @create_merge_request ? @commit.public_send("#{action}_branch_name") : @target_branch - tree_id = repository.public_send("check_#{action}_content", @commit, @target_branch) + if @create_merge_request + into = @commit.public_send("#{action}_branch_name") + tree_branch = @source_branch + else + into = tree_branch = @target_branch + end + + tree_id = repository.public_send( + "check_#{action}_content", @commit, tree_branch) if tree_id validate_target_branch(into) if @create_merge_request diff --git a/lib/api/commits.rb b/lib/api/commits.rb index cf2489dbb67..2c1da0902c9 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -140,8 +140,6 @@ module API commit_params = { commit: commit, create_merge_request: false, - source_project: user_project, - source_branch: commit.cherry_pick_branch_name, target_branch: params[:branch] } -- GitLab