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
65806ec6
Commit
65806ec6
authored
Dec 06, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-enable tests for update_branch_with_hooks and
Add back check if we're losing commits in a merge.
parent
444da6f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
14 deletions
+51
-14
app/services/git_operation_service.rb
app/services/git_operation_service.rb
+13
-2
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+38
-12
No files found.
app/services/git_operation_service.rb
View file @
65806ec6
...
@@ -102,9 +102,20 @@ GitOperationService = Struct.new(:user, :repository) do
...
@@ -102,9 +102,20 @@ GitOperationService = Struct.new(:user, :repository) do
raise
Repository
::
CommitError
.
new
(
'Failed to create commit'
)
raise
Repository
::
CommitError
.
new
(
'Failed to create commit'
)
end
end
service
.
newrev
=
nextrev
branch
=
repository
.
find_branch
(
ref
[
Gitlab
::
Git
::
BRANCH_REF_PREFIX
.
size
..-
1
])
prevrev
=
if
branch
&&
!
repository
.
rugged
.
lookup
(
nextrev
).
parent_ids
.
empty?
repository
.
rugged
.
merge_base
(
nextrev
,
branch
.
dereferenced_target
.
sha
)
else
newrev
end
update_ref!
(
ref
,
nextrev
,
newrev
)
update_ref!
(
ref
,
nextrev
,
prevrev
)
service
.
newrev
=
nextrev
# If repo was empty expire cache
# If repo was empty expire cache
repository
.
after_create
if
was_empty
repository
.
after_create
if
was_empty
...
...
spec/models/repository_spec.rb
View file @
65806ec6
...
@@ -682,33 +682,48 @@ describe Repository, models: true do
...
@@ -682,33 +682,48 @@ describe Repository, models: true do
end
end
end
end
x
describe
'#update_branch_with_hooks'
do
describe
'#update_branch_with_hooks'
do
let
(
:old_rev
)
{
'0b4bc9a49b562e85de7cc9e834518ea6828729b9'
}
# git rev-parse feature
let
(
:old_rev
)
{
'0b4bc9a49b562e85de7cc9e834518ea6828729b9'
}
# git rev-parse feature
let
(
:new_rev
)
{
'a74ae73c1ccde9b974a70e82b901588071dc142a'
}
# commit whose parent is old_rev
let
(
:new_rev
)
{
'a74ae73c1ccde9b974a70e82b901588071dc142a'
}
# commit whose parent is old_rev
context
'when pre hooks were successful'
do
context
'when pre hooks were successful'
do
before
do
before
do
expect_any_instance_of
(
GitHooksService
).
to
receive
(
:execute
).
service
=
GitHooksService
.
new
with
(
user
,
repository
.
path_to_repo
,
old_rev
,
new_rev
,
'refs/heads/feature'
).
expect
(
GitHooksService
).
to
receive
(
:new
).
and_return
(
service
)
and_yield
.
and_return
(
true
)
expect
(
service
).
to
receive
(
:execute
).
with
(
user
,
repository
.
path_to_repo
,
old_rev
,
old_rev
,
'refs/heads/feature'
).
and_yield
(
service
).
and_return
(
true
)
end
end
it
'runs without errors'
do
it
'runs without errors'
do
expect
do
expect
do
repository
.
update_branch_with_hooks
(
user
,
'feature'
)
{
new_rev
}
GitOperationService
.
new
(
user
,
repository
).
with_branch
(
'feature'
)
do
new_rev
end
end
.
not_to
raise_error
end
.
not_to
raise_error
end
end
it
'ensures the autocrlf Git option is set to :input'
do
it
'ensures the autocrlf Git option is set to :input'
do
expect
(
repository
).
to
receive
(
:update_autocrlf_option
)
service
=
GitOperationService
.
new
(
user
,
repository
)
expect
(
service
).
to
receive
(
:update_autocrlf_option
)
repository
.
update_branch_with_hooks
(
user
,
'feature'
)
{
new_rev
}
service
.
with_branch
(
'feature'
)
{
new_rev
}
end
end
context
"when the branch wasn't empty"
do
context
"when the branch wasn't empty"
do
it
'updates the head'
do
it
'updates the head'
do
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
old_rev
)
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
old_rev
)
repository
.
update_branch_with_hooks
(
user
,
'feature'
)
{
new_rev
}
GitOperationService
.
new
(
user
,
repository
).
with_branch
(
'feature'
)
do
new_rev
end
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
new_rev
)
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
new_rev
)
end
end
end
end
...
@@ -727,7 +742,11 @@ describe Repository, models: true do
...
@@ -727,7 +742,11 @@ describe Repository, models: true do
branch
=
'feature-ff-target'
branch
=
'feature-ff-target'
repository
.
add_branch
(
user
,
branch
,
old_rev
)
repository
.
add_branch
(
user
,
branch
,
old_rev
)
expect
{
repository
.
update_branch_with_hooks
(
user
,
branch
)
{
new_rev
}
}.
not_to
raise_error
expect
do
GitOperationService
.
new
(
user
,
repository
).
with_branch
(
branch
)
do
new_rev
end
end
.
not_to
raise_error
end
end
end
end
...
@@ -742,7 +761,9 @@ describe Repository, models: true do
...
@@ -742,7 +761,9 @@ describe Repository, models: true do
# Updating 'master' to new_rev would lose the commits on 'master' that
# Updating 'master' to new_rev would lose the commits on 'master' that
# are not contained in new_rev. This should not be allowed.
# are not contained in new_rev. This should not be allowed.
expect
do
expect
do
repository
.
update_branch_with_hooks
(
user
,
branch
)
{
new_rev
}
GitOperationService
.
new
(
user
,
repository
).
with_branch
(
branch
)
do
new_rev
end
end
.
to
raise_error
(
Repository
::
CommitError
)
end
.
to
raise_error
(
Repository
::
CommitError
)
end
end
end
end
...
@@ -752,7 +773,9 @@ describe Repository, models: true do
...
@@ -752,7 +773,9 @@ describe Repository, models: true do
allow_any_instance_of
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:trigger
).
and_return
([
false
,
''
])
allow_any_instance_of
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:trigger
).
and_return
([
false
,
''
])
expect
do
expect
do
repository
.
update_branch_with_hooks
(
user
,
'feature'
)
{
new_rev
}
GitOperationService
.
new
(
user
,
repository
).
with_branch
(
'feature'
)
do
new_rev
end
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
end
end
end
...
@@ -770,7 +793,10 @@ describe Repository, models: true do
...
@@ -770,7 +793,10 @@ describe Repository, models: true do
expect
(
repository
).
to
receive
(
:expire_branches_cache
)
expect
(
repository
).
to
receive
(
:expire_branches_cache
)
expect
(
repository
).
to
receive
(
:expire_has_visible_content_cache
)
expect
(
repository
).
to
receive
(
:expire_has_visible_content_cache
)
repository
.
update_branch_with_hooks
(
user
,
'new-feature'
)
{
new_rev
}
GitOperationService
.
new
(
user
,
repository
).
with_branch
(
'new-feature'
)
do
new_rev
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