Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bcb605fa
Commit
bcb605fa
authored
Sep 10, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
fa73e107
a9cd5d2a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
53 deletions
+83
-53
app/services/merge_requests/build_service.rb
app/services/merge_requests/build_service.rb
+17
-4
app/views/projects/merge_requests/creations/_new_compare.html.haml
.../projects/merge_requests/creations/_new_compare.html.haml
+1
-1
changelogs/unreleased/fj-62807-not-prefill-target-branch.yml
changelogs/unreleased/fj-62807-not-prefill-target-branch.yml
+5
-0
spec/services/merge_requests/build_service_spec.rb
spec/services/merge_requests/build_service_spec.rb
+60
-48
No files found.
app/services/merge_requests/build_service.rb
View file @
bcb605fa
...
@@ -33,7 +33,8 @@ module MergeRequests
...
@@ -33,7 +33,8 @@ module MergeRequests
merge_request
.
assign_attributes
(
params
.
to_h
.
compact
)
merge_request
.
assign_attributes
(
params
.
to_h
.
compact
)
merge_request
.
compare_commits
=
[]
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?
merge_request
.
can_be_created
=
projects_and_branches_valid?
# compare branches only if branches are valid, otherwise
# compare branches only if branches are valid, otherwise
...
@@ -93,8 +94,12 @@ module MergeRequests
...
@@ -93,8 +94,12 @@ module MergeRequests
project_from_params
project_from_params
end
end
def
find_target_branch
def
set_merge_request_target_branch
target_branch
||
target_project
.
default_branch
if
source_branch_default?
&&
!
target_branch_specified?
merge_request
.
target_branch
=
nil
else
merge_request
.
target_branch
||=
target_project
.
default_branch
end
end
end
def
source_branch_specified?
def
source_branch_specified?
...
@@ -149,7 +154,15 @@ module MergeRequests
...
@@ -149,7 +154,15 @@ module MergeRequests
end
end
def
same_source_and_target?
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
end
def
source_branch_exists?
def
source_branch_exists?
...
...
app/views/projects/merge_requests/creations/_new_compare.html.haml
View file @
bcb605fa
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
selected:
f
.
object
.
target_project_id
selected:
f
.
object
.
target_project_id
.merge-request-select.dropdown
.merge-request-select.dropdown
=
f
.
hidden_field
:target_branch
=
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-menu.dropdown-menu-selectable.js-target-branch-dropdown.git-revision-dropdown
=
dropdown_title
(
_
(
"Select target branch"
))
=
dropdown_title
(
_
(
"Select target branch"
))
=
dropdown_filter
(
_
(
"Search branches"
))
=
dropdown_filter
(
_
(
"Search branches"
))
...
...
changelogs/unreleased/fj-62807-not-prefill-target-branch.yml
0 → 100644
View file @
bcb605fa
---
title
:
Avoid prefilling target branch when source branch is the default one
merge_request
:
32701
author
:
type
:
other
spec/services/merge_requests/build_service_spec.rb
View file @
bcb605fa
...
@@ -49,6 +49,22 @@ describe MergeRequests::BuildService do
...
@@ -49,6 +49,22 @@ describe MergeRequests::BuildService do
allow
(
project
).
to
receive
(
:commit
).
and_return
(
commit_2
)
allow
(
project
).
to
receive
(
:commit
).
and_return
(
commit_2
)
end
end
shared_examples
'allows the merge request to be created'
do
it
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
true
)
end
end
shared_examples
'forbids the merge request from being created'
do
it
'returns that the merge request cannot be created'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
end
it
'adds an error message to the merge request'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
*
Array
(
error_message
))
end
end
describe
'#execute'
do
describe
'#execute'
do
it
'calls the compare service with the correct arguments'
do
it
'calls the compare service with the correct arguments'
do
allow_any_instance_of
(
described_class
).
to
receive
(
:projects_and_branches_valid?
).
and_return
(
true
)
allow_any_instance_of
(
described_class
).
to
receive
(
:projects_and_branches_valid?
).
and_return
(
true
)
...
@@ -79,12 +95,8 @@ describe MergeRequests::BuildService do
...
@@ -79,12 +95,8 @@ describe MergeRequests::BuildService do
context
'missing source branch'
do
context
'missing source branch'
do
let
(
:source_branch
)
{
''
}
let
(
:source_branch
)
{
''
}
it
'forbids the merge request from being created'
do
it_behaves_like
'forbids the merge request from being created'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
let
(
:error_message
)
{
'You must select source and target branch'
}
end
it
'adds an error message to the merge request'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
'You must select source and target branch'
)
end
end
end
end
...
@@ -96,25 +108,44 @@ describe MergeRequests::BuildService do
...
@@ -96,25 +108,44 @@ describe MergeRequests::BuildService do
stub_compare
stub_compare
end
end
context
'when source branch'
do
context
'is not the repository default branch'
do
it
'creates compare object with target branch as default branch'
do
it
'creates compare object with target branch as default branch'
do
expect
(
merge_request
.
compare
).
to
be_present
expect
(
merge_request
.
compare
).
to
be_present
expect
(
merge_request
.
target_branch
).
to
eq
(
project
.
default_branch
)
expect
(
merge_request
.
target_branch
).
to
eq
(
project
.
default_branch
)
end
end
it
'allows the merge request to be created'
do
it_behaves_like
'allows the merge request to be created'
expect
(
merge_request
.
can_be_created
).
to
eq
(
true
)
end
end
end
context
'same source and targe
t branch'
do
context
'the repository defaul
t branch'
do
let
(
:source_branch
)
{
'master'
}
let
(
:source_branch
)
{
'master'
}
it
'forbids the merge request from being created'
do
it_behaves_like
'forbids the merge request from being created'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
let
(
:error_message
)
{
'You must select source and target branch'
}
end
end
it
'adds an error message to the merge request'
do
context
'when source project is different from the target project'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
'You must select different branches'
)
let
(
:target_project
)
{
create
(
:project
,
:public
,
:repository
)
}
let!
(
:project
)
{
fork_project
(
target_project
,
user
,
namespace:
user
.
namespace
,
repository:
true
)
}
let
(
:source_project
)
{
project
}
it
'creates compare object with target branch as default branch'
do
expect
(
merge_request
.
compare
).
to
be_present
expect
(
merge_request
.
target_branch
).
to
eq
(
project
.
default_branch
)
end
it_behaves_like
'allows the merge request to be created'
end
end
end
end
context
'same source and target branch'
do
let
(
:source_branch
)
{
'master'
}
it_behaves_like
'forbids the merge request from being created'
do
let
(
:error_message
)
{
'You must select different branches'
}
end
end
end
end
...
@@ -125,9 +156,7 @@ describe MergeRequests::BuildService do
...
@@ -125,9 +156,7 @@ describe MergeRequests::BuildService do
stub_compare
stub_compare
end
end
it
'allows the merge request to be created'
do
it_behaves_like
'allows the merge request to be created'
expect
(
merge_request
.
can_be_created
).
to
eq
(
true
)
end
it
'adds a WIP prefix to the merge request title'
do
it
'adds a WIP prefix to the merge request title'
do
expect
(
merge_request
.
title
).
to
eq
(
'WIP: Feature branch'
)
expect
(
merge_request
.
title
).
to
eq
(
'WIP: Feature branch'
)
...
@@ -142,9 +171,7 @@ describe MergeRequests::BuildService do
...
@@ -142,9 +171,7 @@ describe MergeRequests::BuildService do
stub_compare
stub_compare
end
end
it
'allows the merge request to be created'
do
it_behaves_like
'allows the merge request to be created'
expect
(
merge_request
.
can_be_created
).
to
eq
(
true
)
end
it
'uses the title of the commit as the title of the merge request'
do
it
'uses the title of the commit as the title of the merge request'
do
expect
(
merge_request
.
title
).
to
eq
(
commit_1
.
safe_message
.
split
(
"
\n
"
).
first
)
expect
(
merge_request
.
title
).
to
eq
(
commit_1
.
safe_message
.
split
(
"
\n
"
).
first
)
...
@@ -254,9 +281,7 @@ describe MergeRequests::BuildService do
...
@@ -254,9 +281,7 @@ describe MergeRequests::BuildService do
stub_compare
stub_compare
end
end
it
'allows the merge request to be created'
do
it_behaves_like
'allows the merge request to be created'
expect
(
merge_request
.
can_be_created
).
to
eq
(
true
)
end
it
'uses the title of the branch as the merge request title'
do
it
'uses the title of the branch as the merge request title'
do
expect
(
merge_request
.
title
).
to
eq
(
'Feature branch'
)
expect
(
merge_request
.
title
).
to
eq
(
'Feature branch'
)
...
@@ -340,12 +365,8 @@ describe MergeRequests::BuildService do
...
@@ -340,12 +365,8 @@ describe MergeRequests::BuildService do
allow
(
project
).
to
receive
(
:commit
).
with
(
target_branch
).
and_return
(
commit_1
)
allow
(
project
).
to
receive
(
:commit
).
with
(
target_branch
).
and_return
(
commit_1
)
end
end
it
'forbids the merge request from being created'
do
it_behaves_like
'forbids the merge request from being created'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
let
(
:error_message
)
{
'Source branch "feature-branch" does not exist'
}
end
it
'adds an error message to the merge request'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
'Source branch "feature-branch" does not exist'
)
end
end
end
end
...
@@ -355,12 +376,8 @@ describe MergeRequests::BuildService do
...
@@ -355,12 +376,8 @@ describe MergeRequests::BuildService do
allow
(
project
).
to
receive
(
:commit
).
with
(
target_branch
).
and_return
(
nil
)
allow
(
project
).
to
receive
(
:commit
).
with
(
target_branch
).
and_return
(
nil
)
end
end
it
'forbids the merge request from being created'
do
it_behaves_like
'forbids the merge request from being created'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
let
(
:error_message
)
{
'Target branch "master" does not exist'
}
end
it
'adds an error message to the merge request'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
'Target branch "master" does not exist'
)
end
end
end
end
...
@@ -369,15 +386,10 @@ describe MergeRequests::BuildService do
...
@@ -369,15 +386,10 @@ describe MergeRequests::BuildService do
allow
(
project
).
to
receive
(
:commit
).
and_return
(
nil
)
allow
(
project
).
to
receive
(
:commit
).
and_return
(
nil
)
end
end
it
'forbids the merge request from being created'
do
it_behaves_like
'forbids the merge request from being created'
do
expect
(
merge_request
.
can_be_created
).
to
eq
(
false
)
let
(
:error_message
)
do
[
'Source branch "feature-branch" does not exist'
,
'Target branch "master" does not exist'
]
end
end
it
'adds both error messages to the merge request'
do
expect
(
merge_request
.
errors
).
to
contain_exactly
(
'Source branch "feature-branch" does not exist'
,
'Target branch "master" does not exist'
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment