diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-09-10 13:41:07 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-09-10 13:41:07 +0000 |
commit | a9cd5d2a378b90a4263793a14d73ad6e2c170889 (patch) | |
tree | fa257798aac9bf354277a6e9dfae96a51cea509c /app | |
parent | 08b0613302ec813c0735e2c0447a3f7683d7ab87 (diff) | |
parent | d1ba86645164c7b06eb558bd8a0c78d6cf6a8de6 (diff) | |
download | gitlab-ce-a9cd5d2a378b90a4263793a14d73ad6e2c170889.tar.gz |
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')
-rw-r--r-- | app/services/merge_requests/build_service.rb | 21 | ||||
-rw-r--r-- | app/views/projects/merge_requests/creations/_new_compare.html.haml | 2 |
2 files changed, 18 insertions, 5 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? diff --git a/app/views/projects/merge_requests/creations/_new_compare.html.haml b/app/views/projects/merge_requests/creations/_new_compare.html.haml index be01905dd35..c6615b26bc0 100644 --- a/app/views/projects/merge_requests/creations/_new_compare.html.haml +++ b/app/views/projects/merge_requests/creations/_new_compare.html.haml @@ -51,7 +51,7 @@ selected: f.object.target_project_id .merge-request-select.dropdown = f.hidden_field :target_branch - = dropdown_toggle f.object.target_branch, { toggle: "dropdown", 'field-name': "#{f.object_name}[target_branch]", 'refs-url': refs_project_path(f.object.target_project), selected: f.object.target_branch }, { toggle_class: "js-compare-dropdown js-target-branch monospace" } + = dropdown_toggle f.object.target_branch || _("Select target branch"), { toggle: "dropdown", 'field-name': "#{f.object_name}[target_branch]", 'refs-url': refs_project_path(f.object.target_project), selected: f.object.target_branch }, { toggle_class: "js-compare-dropdown js-target-branch monospace" } .dropdown-menu.dropdown-menu-selectable.js-target-branch-dropdown.git-revision-dropdown = dropdown_title(_("Select target branch")) = dropdown_filter(_("Search branches")) |