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
a7502691
Commit
a7502691
authored
Sep 07, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow adding multiple commits in commit_with_hooks
parent
a83c5ff4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
app/models/repository.rb
app/models/repository.rb
+5
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+19
-0
No files found.
app/models/repository.rb
View file @
a7502691
...
@@ -1040,7 +1040,11 @@ class Repository
...
@@ -1040,7 +1040,11 @@ class Repository
raise
CommitError
.
new
(
'Failed to create commit'
)
raise
CommitError
.
new
(
'Failed to create commit'
)
end
end
oldrev
=
rugged
.
lookup
(
newrev
).
parent_ids
.
first
||
Gitlab
::
Git
::
BLANK_SHA
if
rugged
.
lookup
(
newrev
).
parent_ids
.
empty?
||
target_branch
.
nil?
oldrev
=
Gitlab
::
Git
::
BLANK_SHA
else
oldrev
=
rugged
.
merge_base
(
newrev
,
target_branch
.
target
.
sha
)
end
GitHooksService
.
new
.
execute
(
current_user
,
path_to_repo
,
oldrev
,
newrev
,
ref
)
do
GitHooksService
.
new
.
execute
(
current_user
,
path_to_repo
,
oldrev
,
newrev
,
ref
)
do
update_ref!
(
ref
,
newrev
,
oldrev
)
update_ref!
(
ref
,
newrev
,
oldrev
)
...
...
spec/models/repository_spec.rb
View file @
a7502691
...
@@ -473,6 +473,25 @@ describe Repository, models: true do
...
@@ -473,6 +473,25 @@ describe Repository, models: true do
end
end
end
end
context
'when the update adds more than one commit'
do
it
'runs without errors'
do
old_rev
=
'33f3729a45c02fc67d00adb1b8bca394b0e761d9'
# ancestor of new_rev by more than one commit
branch
=
'feature-ff-target'
repository
.
add_branch
(
user
,
branch
,
old_rev
)
expect
{
repository
.
commit_with_hooks
(
user
,
branch
)
{
new_rev
}
}.
not_to
raise_error
end
end
context
'when the update would remove commits from the target branch'
do
it
'raises an exception'
do
# We use the fact that 'master' has diverged from 'feature' (new_rev):
# updating 'master' to new_rev would make us lose commits, which should
# not happen.
expect
{
repository
.
commit_with_hooks
(
user
,
'master'
)
{
new_rev
}
}.
to
raise_error
(
Repository
::
CommitError
)
end
end
context
'when pre hooks failed'
do
context
'when pre hooks failed'
do
it
'gets an error'
do
it
'gets an error'
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
,
''
])
...
...
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