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
3a6967ae
Commit
3a6967ae
authored
Nov 18, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move identical merged branch check to merged_branch_names
parent
1f774de6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
32 deletions
+27
-32
app/models/repository.rb
app/models/repository.rb
+2
-8
app/views/projects/branches/index.html.haml
app/views/projects/branches/index.html.haml
+1
-1
lib/api/entities.rb
lib/api/entities.rb
+5
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+13
-3
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+6
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+0
-18
No files found.
app/models/repository.rb
View file @
3a6967ae
...
...
@@ -916,19 +916,13 @@ class Repository
end
end
def
merged_to_root_ref?
(
branch_or_name
,
pre_loaded_merged_branches
=
nil
)
def
merged_to_root_ref?
(
branch_or_name
)
branch
=
Gitlab
::
Git
::
Branch
.
find
(
self
,
branch_or_name
)
if
branch
@root_ref_sha
||=
commit
(
root_ref
).
sha
same_head
=
branch
.
target
==
@root_ref_sha
merged
=
if
pre_loaded_merged_branches
pre_loaded_merged_branches
.
include?
(
branch
.
name
)
else
ancestor?
(
branch
.
target
,
@root_ref_sha
)
end
merged
=
ancestor?
(
branch
.
target
,
@root_ref_sha
)
!
same_head
&&
merged
else
nil
...
...
app/views/projects/branches/index.html.haml
View file @
3a6967ae
...
...
@@ -41,7 +41,7 @@
-
if
@branches
.
any?
%ul
.content-list.all-branches
-
@branches
.
each
do
|
branch
|
=
render
"projects/branches/branch"
,
branch:
branch
,
merged:
@
repository
.
merged_to_root_ref?
(
branch
,
@merged_branch_names
)
=
render
"projects/branches/branch"
,
branch:
branch
,
merged:
@
merged_branch_names
.
include?
(
branch
.
name
)
=
paginate
@branches
,
theme:
'gitlab'
-
else
.nothing-here-block
...
...
lib/api/entities.rb
View file @
3a6967ae
...
...
@@ -271,7 +271,11 @@ module API
end
expose
:merged
do
|
repo_branch
,
options
|
options
[
:project
].
repository
.
merged_to_root_ref?
(
repo_branch
,
options
[
:merged_branch_names
])
if
options
[
:merged_branch_names
]
options
[
:merged_branch_names
].
include?
(
repo_branch
.
name
)
else
options
[
:project
].
repository
.
merged_to_root_ref?
(
repo_branch
)
end
end
expose
:protected
do
|
repo_branch
,
options
|
...
...
lib/gitlab/git/repository.rb
View file @
3a6967ae
...
...
@@ -1222,11 +1222,21 @@ module Gitlab
sort_branches
(
branches
,
sort_by
)
end
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/695
def
git_merged_branch_names
(
branch_names
=
[])
lines
=
run_git
([
'branch'
,
'--merged'
,
root_ref
]
+
branch_names
)
.
first
.
lines
root_sha
=
find_branch
(
root_ref
).
target
lines
.
map
(
&
:strip
)
git_arguments
=
%W[branch --merged
#{
root_sha
}
--format=%(refname:short)
\
%(objectname)]
+
branch_names
lines
=
run_git
(
git_arguments
).
first
.
lines
lines
.
each_with_object
([])
do
|
line
,
branches
|
name
,
sha
=
line
.
strip
.
split
(
' '
,
2
)
branches
<<
name
if
sha
!=
root_sha
end
end
def
log_using_shell?
(
options
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
3a6967ae
...
...
@@ -1211,12 +1211,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
context
'when no branch names are specified'
do
it
'returns all merged branch names'
do
before
do
repository
.
create_branch
(
'identical'
,
'master'
)
end
it
'returns all merged branch names except for identical one'
do
names
=
repository
.
merged_branch_names
expect
(
names
).
to
include
(
'merge-test'
)
expect
(
names
).
to
include
(
'fix-mode'
)
expect
(
names
).
not_to
include
(
'feature'
)
expect
(
names
).
not_to
include
(
'identical'
)
end
end
end
...
...
spec/models/repository_spec.rb
View file @
3a6967ae
...
...
@@ -299,24 +299,6 @@ describe Repository do
it
{
is_expected
.
to
be_falsey
}
end
context
'when pre-loaded merged branches are provided'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:branch
,
:pre_loaded
,
:expected
)
do
'not-merged-branch'
|
[
'branch-merged'
]
|
false
'branch-merged'
|
[
'not-merged-branch'
]
|
false
'branch-merged'
|
[
'branch-merged'
]
|
true
'not-merged-branch'
|
[
'not-merged-branch'
]
|
false
'master'
|
[
'master'
]
|
false
end
with_them
do
subject
{
repository
.
merged_to_root_ref?
(
branch
,
pre_loaded
)
}
it
{
is_expected
.
to
eq
(
expected
)
}
end
end
end
describe
'#can_be_merged?'
do
...
...
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