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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
419d8cc7
Commit
419d8cc7
authored
Sep 28, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calculate modified paths of a git push operation
parent
4abba289
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
3 deletions
+72
-3
lib/gitlab/git/diff_stats_collection.rb
lib/gitlab/git/diff_stats_collection.rb
+4
-0
lib/gitlab/git/push.rb
lib/gitlab/git/push.rb
+14
-0
spec/lib/gitlab/git/diff_stats_collection_spec.rb
spec/lib/gitlab/git/diff_stats_collection_spec.rb
+7
-1
spec/lib/gitlab/git/push_spec.rb
spec/lib/gitlab/git/push_spec.rb
+47
-2
No files found.
lib/gitlab/git/diff_stats_collection.rb
View file @
419d8cc7
...
@@ -18,6 +18,10 @@ module Gitlab
...
@@ -18,6 +18,10 @@ module Gitlab
indexed_by_path
[
path
]
indexed_by_path
[
path
]
end
end
def
paths
@collection
.
map
(
&
:path
)
end
private
private
def
indexed_by_path
def
indexed_by_path
...
...
lib/gitlab/git/push.rb
View file @
419d8cc7
...
@@ -28,6 +28,10 @@ module Gitlab
...
@@ -28,6 +28,10 @@ module Gitlab
Gitlab
::
Git
.
blank_ref?
(
@newrev
)
Gitlab
::
Git
.
blank_ref?
(
@newrev
)
end
end
def
branch_updated?
branch_push?
&&
!
branch_added?
&&
!
branch_removed?
end
def
force_push?
def
force_push?
Gitlab
::
Checks
::
ForcePush
.
force_push?
(
@project
,
@oldrev
,
@newrev
)
Gitlab
::
Checks
::
ForcePush
.
force_push?
(
@project
,
@oldrev
,
@newrev
)
end
end
...
@@ -37,6 +41,16 @@ module Gitlab
...
@@ -37,6 +41,16 @@ module Gitlab
Gitlab
::
Git
.
branch_ref?
(
@ref
)
Gitlab
::
Git
.
branch_ref?
(
@ref
)
end
end
end
end
def
modified_paths
unless
branch_updated?
raise
ArgumentError
,
'Unable to calculate modified paths!'
end
strong_memoize
(
:modified_paths
)
do
@project
.
repository
.
diff_stats
(
@oldrev
,
@newrev
).
paths
end
end
end
end
end
end
end
end
spec/lib/gitlab/git/diff_stats_collection_spec.rb
View file @
419d8cc7
...
@@ -14,7 +14,7 @@ describe Gitlab::Git::DiffStatsCollection do
...
@@ -14,7 +14,7 @@ describe Gitlab::Git::DiffStatsCollection do
let
(
:diff_stats
)
{
[
stats_a
,
stats_b
]
}
let
(
:diff_stats
)
{
[
stats_a
,
stats_b
]
}
let
(
:collection
)
{
described_class
.
new
(
diff_stats
)
}
let
(
:collection
)
{
described_class
.
new
(
diff_stats
)
}
describe
'
.
find_by_path'
do
describe
'
#
find_by_path'
do
it
'returns stats by path when found'
do
it
'returns stats by path when found'
do
expect
(
collection
.
find_by_path
(
'foo'
)).
to
eq
(
stats_a
)
expect
(
collection
.
find_by_path
(
'foo'
)).
to
eq
(
stats_a
)
end
end
...
@@ -23,4 +23,10 @@ describe Gitlab::Git::DiffStatsCollection do
...
@@ -23,4 +23,10 @@ describe Gitlab::Git::DiffStatsCollection do
expect
(
collection
.
find_by_path
(
'no-file'
)).
to
be_nil
expect
(
collection
.
find_by_path
(
'no-file'
)).
to
be_nil
end
end
end
end
describe
'#paths'
do
it
'returns only modified paths'
do
expect
(
collection
.
paths
).
to
eq
%w[foo bar]
end
end
end
end
spec/lib/gitlab/git/push_spec.rb
View file @
419d8cc7
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
Git
::
Push
do
describe
Gitlab
::
Git
::
Push
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:oldrev
)
{
project
.
commit
(
'HEAD~
10
'
).
id
}
let
(
:oldrev
)
{
project
.
commit
(
'HEAD~
2
'
).
id
}
let
(
:newrev
)
{
project
.
commit
.
id
}
let
(
:newrev
)
{
project
.
commit
.
id
}
let
(
:ref
)
{
'refs/heads/some-branch'
}
let
(
:ref
)
{
'refs/heads/some-branch'
}
...
@@ -35,12 +35,36 @@ describe Gitlab::Git::Push do
...
@@ -35,12 +35,36 @@ describe Gitlab::Git::Push do
end
end
context
'when it is a tag push'
do
context
'when it is a tag push'
do
let
(
:ref
)
{
'refs/tags/my-
branch
'
}
let
(
:ref
)
{
'refs/tags/my-
tag
'
}
it
{
is_expected
.
not_to
be_branch_push
}
it
{
is_expected
.
not_to
be_branch_push
}
end
end
end
end
describe
'#branch_updated?'
do
context
'when it is a branch push with correct old and new revisions'
do
it
{
is_expected
.
to
be_branch_updated
}
end
context
'when it is not a branch push'
do
let
(
:ref
)
{
'refs/tags/my-tag'
}
it
{
is_expected
.
not_to
be_branch_updated
}
end
context
'when old revision is blank'
do
let
(
:oldrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
it
{
is_expected
.
not_to
be_branch_updated
}
end
context
'when it is not a branch push'
do
let
(
:newrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
it
{
is_expected
.
not_to
be_branch_updated
}
end
end
describe
'#force_push?'
do
describe
'#force_push?'
do
context
'when old revision is an ancestor of the new revision'
do
context
'when old revision is an ancestor of the new revision'
do
let
(
:oldrev
)
{
'HEAD~3'
}
let
(
:oldrev
)
{
'HEAD~3'
}
...
@@ -80,4 +104,25 @@ describe Gitlab::Git::Push do
...
@@ -80,4 +104,25 @@ describe Gitlab::Git::Push do
it
{
is_expected
.
to
be_branch_removed
}
it
{
is_expected
.
to
be_branch_removed
}
end
end
end
end
describe
'#modified_paths'
do
context
'when a push is a branch update'
do
let
(
:oldrev
)
{
'281d3a76f31c812dbf48abce82ccf6860adedd81'
}
let
(
:new_rev
)
{
'1b12f15a11fc6e62177bef08f47bc7b5ce50b141'
}
it
'returns modified paths'
do
expect
(
subject
.
modified_paths
).
to
eq
[
'bar/branch-test.txt'
,
'files/js/commit.coffee'
,
'with space/README.md'
]
end
end
context
'when a push is not a branch update'
do
let
(
:oldrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
it
'raises an error'
do
expect
{
subject
.
modified_paths
}.
to
raise_error
(
ArgumentError
)
end
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