From 358501df2d3229f68be700d2fc57cd3c3e7e5042 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 6 Jan 2017 22:20:02 +0800 Subject: Properly fix the edge case! --- app/controllers/concerns/creates_commit.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/controllers/concerns/creates_commit.rb') diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index c503f8bf696..516b1cac6ef 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -97,8 +97,6 @@ module CreatesCommit # TODO: We should really clean this up def set_commit_variables - @mr_source_branch = @target_branch unless create_merge_request? - if can?(current_user, :push_code, @project) # Edit file in this project @tree_edit_project = @project @@ -121,10 +119,25 @@ module CreatesCommit @mr_target_project = @project @mr_target_branch = @ref || @target_branch end + + @mr_source_branch = guess_mr_source_branch end def initial_commit? @mr_target_branch.nil? || !@mr_target_project.repository.branch_exists?(@mr_target_branch) end + + def guess_mr_source_branch + # XXX: Happens when viewing a commit without a branch. In this case, + # @target_branch would be the default branch for @mr_source_project, + # however we want a generated new branch here. Thus we can't use + # @target_branch, but should pass nil to indicate that we want a new + # branch instead of @target_branch. + return if + create_merge_request? && + @mr_source_project.repository.branch_exists?(@target_branch) + + @target_branch + end end -- cgit v1.2.1