diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-09-10 16:41:07 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-09-10 16:41:07 +0300 |
commit | a9cd5d2a378b90a4263793a14d73ad6e2c170889 (patch) | |
tree | fa257798aac9bf354277a6e9dfae96a51cea509c /app/services/merge_requests | |
parent | 08b0613302ec813c0735e2c0447a3f7683d7ab87 (diff) | |
parent | d1ba86645164c7b06eb558bd8a0c78d6cf6a8de6 (diff) |
Merge branch 'fj-62807-not-prefill-target-branch' into 'master'
Avoid filling target branch when unknown and source is default branch
Closes #62807
See merge request gitlab-org/gitlab-ce!32701
Diffstat (limited to 'app/services/merge_requests')
-rw-r--r-- | app/services/merge_requests/build_service.rb | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index 308a3a10d1a..88ed0c3ef4c 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -33,7 +33,8 @@ module MergeRequests merge_request.assign_attributes(params.to_h.compact) merge_request.compare_commits = [] - merge_request.target_branch = find_target_branch + set_merge_request_target_branch + merge_request.can_be_created = projects_and_branches_valid? # compare branches only if branches are valid, otherwise @@ -93,8 +94,12 @@ module MergeRequests project_from_params end - def find_target_branch - target_branch || target_project.default_branch + def set_merge_request_target_branch + if source_branch_default? && !target_branch_specified? + merge_request.target_branch = nil + else + merge_request.target_branch ||= target_project.default_branch + end end def source_branch_specified? @@ -149,7 +154,15 @@ module MergeRequests end def same_source_and_target? - source_project == target_project && target_branch == source_branch + same_source_and_target_project? && target_branch == source_branch + end + + def source_branch_default? + same_source_and_target_project? && source_branch == target_project.default_branch + end + + def same_source_and_target_project? + source_project == target_project end def source_branch_exists? |