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
5e6a5270
Commit
5e6a5270
authored
Dec 01, 2015
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise the exception from #execute instead of #run_hook. #1156 #3069
parent
338eb2c4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
13 deletions
+15
-13
app/services/git_hooks_service.rb
app/services/git_hooks_service.rb
+9
-11
spec/services/git_hooks_service_spec.rb
spec/services/git_hooks_service_spec.rb
+6
-2
No files found.
app/services/git_hooks_service.rb
View file @
5e6a5270
...
@@ -8,23 +8,21 @@ class GitHooksService
...
@@ -8,23 +8,21 @@ class GitHooksService
@newrev
=
newrev
@newrev
=
newrev
@ref
=
ref
@ref
=
ref
if
run_hook
(
'pre-receive'
)
&&
run_hook
(
'update'
)
%w(pre-receive update)
.
each
do
|
hook_name
|
unless
run_hook
(
hook_name
)
raise
PreReceiveError
.
new
(
"Git operation was rejected by
#{
hook_name
}
hook"
)
end
end
yield
yield
run_hook
(
'post-receive'
)
run_hook
(
'post-receive'
)
end
end
end
private
private
def
run_hook
(
name
)
def
run_hook
(
name
)
hook
=
Gitlab
::
Git
::
Hook
.
new
(
name
,
@repo_path
)
hook
=
Gitlab
::
Git
::
Hook
.
new
(
name
,
@repo_path
)
status
=
hook
.
trigger
(
@user
,
@oldrev
,
@newrev
,
@ref
)
hook
.
trigger
(
@user
,
@oldrev
,
@newrev
,
@ref
)
if
!
status
&&
(
name
!=
'post-receive'
)
raise
PreReceiveError
.
new
(
"Git operation was rejected by
#{
name
}
hook"
)
end
status
end
end
end
end
spec/services/git_hooks_service_spec.rb
View file @
5e6a5270
...
@@ -31,7 +31,9 @@ describe GitHooksService do
...
@@ -31,7 +31,9 @@ describe GitHooksService do
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'pre-receive'
).
and_return
(
false
)
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'pre-receive'
).
and_return
(
false
)
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
do
service
.
execute
(
user
,
@repo_path
,
@blankrev
,
@newrev
,
@ref
)
service
.
execute
(
user
,
@repo_path
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
end
end
end
end
...
@@ -41,7 +43,9 @@ describe GitHooksService do
...
@@ -41,7 +43,9 @@ describe GitHooksService do
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'update'
).
and_return
(
false
)
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'update'
).
and_return
(
false
)
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
do
service
.
execute
(
user
,
@repo_path
,
@blankrev
,
@newrev
,
@ref
)
service
.
execute
(
user
,
@repo_path
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
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