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
Léo-Paul Géneau
gitlab-ce
Commits
ea8dc107
Commit
ea8dc107
authored
Jun 11, 2018
by
Jacob Vosmaer (GitLab)
Committed by
Sean McGivern
Jun 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use Gitlab::Utils.nlbr in Gitlab::Git
parent
8742af1e
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
82 additions
and
47 deletions
+82
-47
app/services/commits/create_service.rb
app/services/commits/create_service.rb
+1
-1
app/services/create_branch_service.rb
app/services/create_branch_service.rb
+1
-1
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+1
-1
app/services/merge_requests/ff_merge_service.rb
app/services/merge_requests/ff_merge_service.rb
+1
-1
app/services/merge_requests/merge_service.rb
app/services/merge_requests/merge_service.rb
+1
-1
app/services/tags/create_service.rb
app/services/tags/create_service.rb
+1
-1
app/services/tags/destroy_service.rb
app/services/tags/destroy_service.rb
+1
-1
app/services/validate_new_branch_service.rb
app/services/validate_new_branch_service.rb
+1
-1
lib/gitlab/git/committer_with_hooks.rb
lib/gitlab/git/committer_with_hooks.rb
+1
-1
lib/gitlab/git/hook.rb
lib/gitlab/git/hook.rb
+3
-3
lib/gitlab/git/hooks_service.rb
lib/gitlab/git/hooks_service.rb
+0
-2
lib/gitlab/git/pre_receive_error.rb
lib/gitlab/git/pre_receive_error.rb
+21
-0
lib/gitlab/gitaly_client/operation_service.rb
lib/gitlab/gitaly_client/operation_service.rb
+8
-8
spec/features/tags/master_deletes_tag_spec.rb
spec/features/tags/master_deletes_tag_spec.rb
+2
-2
spec/lib/gitlab/git/hook_spec.rb
spec/lib/gitlab/git/hook_spec.rb
+16
-9
spec/lib/gitlab/git/hooks_service_spec.rb
spec/lib/gitlab/git/hooks_service_spec.rb
+4
-4
spec/lib/gitlab/git/pre_receive_error_spec.rb
spec/lib/gitlab/git/pre_receive_error_spec.rb
+9
-0
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
+2
-2
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+5
-5
spec/services/merge_requests/ff_merge_service_spec.rb
spec/services/merge_requests/ff_merge_service_spec.rb
+1
-1
spec/services/merge_requests/merge_service_spec.rb
spec/services/merge_requests/merge_service_spec.rb
+1
-1
spec/services/tags/create_service_spec.rb
spec/services/tags/create_service_spec.rb
+1
-1
No files found.
app/services/commits/create_service.rb
View file @
ea8dc107
...
@@ -17,7 +17,7 @@ module Commits
...
@@ -17,7 +17,7 @@ module Commits
new_commit
=
create_commit!
new_commit
=
create_commit!
success
(
result:
new_commit
)
success
(
result:
new_commit
)
rescue
ValidationError
,
ChangeError
,
Gitlab
::
Git
::
Index
::
IndexError
,
Gitlab
::
Git
::
CommitError
,
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
ValidationError
,
ChangeError
,
Gitlab
::
Git
::
Index
::
IndexError
,
Gitlab
::
Git
::
CommitError
,
Gitlab
::
Git
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/create_branch_service.rb
View file @
ea8dc107
...
@@ -14,7 +14,7 @@ class CreateBranchService < BaseService
...
@@ -14,7 +14,7 @@ class CreateBranchService < BaseService
else
else
error
(
'Invalid reference name'
)
error
(
'Invalid reference name'
)
end
end
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
Gitlab
::
Git
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/delete_branch_service.rb
View file @
ea8dc107
...
@@ -16,7 +16,7 @@ class DeleteBranchService < BaseService
...
@@ -16,7 +16,7 @@ class DeleteBranchService < BaseService
else
else
error
(
'Failed to remove branch'
)
error
(
'Failed to remove branch'
)
end
end
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
Gitlab
::
Git
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/merge_requests/ff_merge_service.rb
View file @
ea8dc107
...
@@ -13,7 +13,7 @@ module MergeRequests
...
@@ -13,7 +13,7 @@ module MergeRequests
source
,
source
,
merge_request
.
target_branch
,
merge_request
.
target_branch
,
merge_request:
merge_request
)
merge_request:
merge_request
)
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
e
rescue
Gitlab
::
Git
::
PreReceiveError
=>
e
raise
MergeError
,
e
.
message
raise
MergeError
,
e
.
message
rescue
StandardError
=>
e
rescue
StandardError
=>
e
raise
MergeError
,
"Something went wrong during merge:
#{
e
.
message
}
"
raise
MergeError
,
"Something went wrong during merge:
#{
e
.
message
}
"
...
...
app/services/merge_requests/merge_service.rb
View file @
ea8dc107
...
@@ -79,7 +79,7 @@ module MergeRequests
...
@@ -79,7 +79,7 @@ module MergeRequests
message
=
params
[
:commit_message
]
||
merge_request
.
merge_commit_message
message
=
params
[
:commit_message
]
||
merge_request
.
merge_commit_message
repository
.
merge
(
current_user
,
source
,
merge_request
,
message
)
repository
.
merge
(
current_user
,
source
,
merge_request
,
message
)
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
e
rescue
Gitlab
::
Git
::
PreReceiveError
=>
e
handle_merge_error
(
log_message:
e
.
message
)
handle_merge_error
(
log_message:
e
.
message
)
raise
MergeError
,
'Something went wrong during merge pre-receive hook'
raise
MergeError
,
'Something went wrong during merge pre-receive hook'
rescue
=>
e
rescue
=>
e
...
...
app/services/tags/create_service.rb
View file @
ea8dc107
...
@@ -13,7 +13,7 @@ module Tags
...
@@ -13,7 +13,7 @@ module Tags
new_tag
=
repository
.
add_tag
(
current_user
,
tag_name
,
target
,
message
)
new_tag
=
repository
.
add_tag
(
current_user
,
tag_name
,
target
,
message
)
rescue
Gitlab
::
Git
::
Repository
::
TagExistsError
rescue
Gitlab
::
Git
::
Repository
::
TagExistsError
return
error
(
"Tag
#{
tag_name
}
already exists"
)
return
error
(
"Tag
#{
tag_name
}
already exists"
)
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
Gitlab
::
Git
::
PreReceiveError
=>
ex
return
error
(
ex
.
message
)
return
error
(
ex
.
message
)
end
end
...
...
app/services/tags/destroy_service.rb
View file @
ea8dc107
...
@@ -21,7 +21,7 @@ module Tags
...
@@ -21,7 +21,7 @@ module Tags
else
else
error
(
'Failed to remove tag'
)
error
(
'Failed to remove tag'
)
end
end
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
Gitlab
::
Git
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
...
...
app/services/validate_new_branch_service.rb
View file @
ea8dc107
...
@@ -13,7 +13,7 @@ class ValidateNewBranchService < BaseService
...
@@ -13,7 +13,7 @@ class ValidateNewBranchService < BaseService
end
end
success
success
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
Gitlab
::
Git
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
end
end
end
end
lib/gitlab/git/committer_with_hooks.rb
View file @
ea8dc107
...
@@ -20,7 +20,7 @@ module Gitlab
...
@@ -20,7 +20,7 @@ module Gitlab
end
end
result
[
:newrev
]
result
[
:newrev
]
rescue
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
e
rescue
Gitlab
::
Git
::
PreReceiveError
=>
e
message
=
"Custom Hook failed:
#{
e
.
message
}
"
message
=
"Custom Hook failed:
#{
e
.
message
}
"
raise
Gitlab
::
Git
::
Wiki
::
OperationError
,
message
raise
Gitlab
::
Git
::
Wiki
::
OperationError
,
message
end
end
...
...
lib/gitlab/git/hook.rb
View file @
ea8dc107
...
@@ -11,7 +11,7 @@ module Gitlab
...
@@ -11,7 +11,7 @@ module Gitlab
def
initialize
(
name
,
repository
)
def
initialize
(
name
,
repository
)
@name
=
name
@name
=
name
@repository
=
repository
@repository
=
repository
@path
=
File
.
join
(
repo_path
.
strip
,
'hooks'
,
name
)
@path
=
File
.
join
(
repo_path
,
'hooks'
,
name
)
end
end
def
repo_path
def
repo_path
...
@@ -95,13 +95,13 @@ module Gitlab
...
@@ -95,13 +95,13 @@ module Gitlab
args
=
[
ref
,
oldrev
,
newrev
]
args
=
[
ref
,
oldrev
,
newrev
]
stdout
,
stderr
,
status
=
Open3
.
capture3
(
env
,
path
,
*
args
,
options
)
stdout
,
stderr
,
status
=
Open3
.
capture3
(
env
,
path
,
*
args
,
options
)
[
status
.
success?
,
Gitlab
::
Utils
.
nlbr
(
stderr
.
presence
||
stdout
)
]
[
status
.
success?
,
stderr
.
presence
||
stdout
]
end
end
def
retrieve_error_message
(
stderr
,
stdout
)
def
retrieve_error_message
(
stderr
,
stdout
)
err_message
=
stderr
.
read
err_message
=
stderr
.
read
err_message
=
err_message
.
blank?
?
stdout
.
read
:
err_message
err_message
=
err_message
.
blank?
?
stdout
.
read
:
err_message
Gitlab
::
Utils
.
nlbr
(
err_message
)
err_message
end
end
end
end
end
end
...
...
lib/gitlab/git/hooks_service.rb
View file @
ea8dc107
module
Gitlab
module
Gitlab
module
Git
module
Git
class
HooksService
class
HooksService
PreReceiveError
=
Class
.
new
(
StandardError
)
attr_accessor
:oldrev
,
:newrev
,
:ref
attr_accessor
:oldrev
,
:newrev
,
:ref
def
execute
(
pusher
,
repository
,
oldrev
,
newrev
,
ref
)
def
execute
(
pusher
,
repository
,
oldrev
,
newrev
,
ref
)
...
...
lib/gitlab/git/pre_receive_error.rb
0 → 100644
View file @
ea8dc107
module
Gitlab
module
Git
#
# PreReceiveError is special because its message gets displayed to users
# in the web UI. To prevent XSS we sanitize the message on
# initialization.
class
PreReceiveError
<
StandardError
def
initialize
(
msg
=
''
)
super
(
nlbr
(
msg
))
end
private
# In gitaly-ruby we override this method to do nothing, so that
# sanitization happens in gitlab-rails only.
def
nlbr
(
str
)
Gitlab
::
Utils
.
nlbr
(
str
)
end
end
end
end
lib/gitlab/gitaly_client/operation_service.rb
View file @
ea8dc107
...
@@ -20,7 +20,7 @@ module Gitlab
...
@@ -20,7 +20,7 @@ module Gitlab
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_delete_tag
,
request
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_delete_tag
,
request
)
if
pre_receive_error
=
response
.
pre_receive_error
.
presence
if
pre_receive_error
=
response
.
pre_receive_error
.
presence
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
pre_receive_error
end
end
end
end
...
@@ -35,7 +35,7 @@ module Gitlab
...
@@ -35,7 +35,7 @@ module Gitlab
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_create_tag
,
request
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_create_tag
,
request
)
if
pre_receive_error
=
response
.
pre_receive_error
.
presence
if
pre_receive_error
=
response
.
pre_receive_error
.
presence
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
pre_receive_error
elsif
response
.
exists
elsif
response
.
exists
raise
Gitlab
::
Git
::
Repository
::
TagExistsError
raise
Gitlab
::
Git
::
Repository
::
TagExistsError
end
end
...
@@ -56,7 +56,7 @@ module Gitlab
...
@@ -56,7 +56,7 @@ module Gitlab
:user_create_branch
,
request
)
:user_create_branch
,
request
)
if
response
.
pre_receive_error
.
present?
if
response
.
pre_receive_error
.
present?
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
.
new
(
response
.
pre_receive_error
)
raise
Gitlab
::
Git
::
PreReceiveError
.
new
(
response
.
pre_receive_error
)
end
end
branch
=
response
.
branch
branch
=
response
.
branch
...
@@ -76,7 +76,7 @@ module Gitlab
...
@@ -76,7 +76,7 @@ module Gitlab
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_delete_branch
,
request
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:operation_service
,
:user_delete_branch
,
request
)
if
pre_receive_error
=
response
.
pre_receive_error
.
presence
if
pre_receive_error
=
response
.
pre_receive_error
.
presence
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
pre_receive_error
end
end
end
end
...
@@ -106,7 +106,7 @@ module Gitlab
...
@@ -106,7 +106,7 @@ module Gitlab
second_response
=
response_enum
.
next
second_response
=
response_enum
.
next
if
second_response
.
pre_receive_error
.
present?
if
second_response
.
pre_receive_error
.
present?
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
second_response
.
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
second_response
.
pre_receive_error
end
end
branch_update
=
second_response
.
branch_update
branch_update
=
second_response
.
branch_update
...
@@ -175,7 +175,7 @@ module Gitlab
...
@@ -175,7 +175,7 @@ module Gitlab
)
)
if
response
.
pre_receive_error
.
presence
if
response
.
pre_receive_error
.
presence
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
response
.
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
response
.
pre_receive_error
elsif
response
.
git_error
.
presence
elsif
response
.
git_error
.
presence
raise
Gitlab
::
Git
::
Repository
::
GitError
,
response
.
git_error
raise
Gitlab
::
Git
::
Repository
::
GitError
,
response
.
git_error
else
else
...
@@ -242,7 +242,7 @@ module Gitlab
...
@@ -242,7 +242,7 @@ module Gitlab
:user_commit_files
,
req_enum
,
remote_storage:
start_repository
.
storage
)
:user_commit_files
,
req_enum
,
remote_storage:
start_repository
.
storage
)
if
(
pre_receive_error
=
response
.
pre_receive_error
.
presence
)
if
(
pre_receive_error
=
response
.
pre_receive_error
.
presence
)
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
pre_receive_error
end
end
if
(
index_error
=
response
.
index_error
.
presence
)
if
(
index_error
=
response
.
index_error
.
presence
)
...
@@ -280,7 +280,7 @@ module Gitlab
...
@@ -280,7 +280,7 @@ module Gitlab
def
handle_cherry_pick_or_revert_response
(
response
)
def
handle_cherry_pick_or_revert_response
(
response
)
if
response
.
pre_receive_error
.
presence
if
response
.
pre_receive_error
.
presence
raise
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
response
.
pre_receive_error
raise
Gitlab
::
Git
::
PreReceiveError
,
response
.
pre_receive_error
elsif
response
.
commit_error
.
presence
elsif
response
.
commit_error
.
presence
raise
Gitlab
::
Git
::
CommitError
,
response
.
commit_error
raise
Gitlab
::
Git
::
CommitError
,
response
.
commit_error
elsif
response
.
create_tree_error
.
presence
elsif
response
.
create_tree_error
.
presence
...
...
spec/features/tags/master_deletes_tag_spec.rb
View file @
ea8dc107
...
@@ -38,7 +38,7 @@ feature 'Master deletes tag' do
...
@@ -38,7 +38,7 @@ feature 'Master deletes tag' do
context
'when Gitaly operation_user_delete_tag feature is enabled'
do
context
'when Gitaly operation_user_delete_tag feature is enabled'
do
before
do
before
do
allow_any_instance_of
(
Gitlab
::
GitalyClient
::
OperationService
).
to
receive
(
:rm_tag
)
allow_any_instance_of
(
Gitlab
::
GitalyClient
::
OperationService
).
to
receive
(
:rm_tag
)
.
and_raise
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
'Do not delete tags'
)
.
and_raise
(
Gitlab
::
Git
::
PreReceiveError
,
'Do not delete tags'
)
end
end
scenario
'shows the error message'
do
scenario
'shows the error message'
do
...
@@ -51,7 +51,7 @@ feature 'Master deletes tag' do
...
@@ -51,7 +51,7 @@ feature 'Master deletes tag' do
context
'when Gitaly operation_user_delete_tag feature is disabled'
,
:skip_gitaly_mock
do
context
'when Gitaly operation_user_delete_tag feature is disabled'
,
:skip_gitaly_mock
do
before
do
before
do
allow_any_instance_of
(
Gitlab
::
Git
::
HooksService
).
to
receive
(
:execute
)
allow_any_instance_of
(
Gitlab
::
Git
::
HooksService
).
to
receive
(
:execute
)
.
and_raise
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
'Do not delete tags'
)
.
and_raise
(
Gitlab
::
Git
::
PreReceiveError
,
'Do not delete tags'
)
end
end
scenario
'shows the error message'
do
scenario
'shows the error message'
do
...
...
spec/lib/gitlab/git/hook_spec.rb
View file @
ea8dc107
...
@@ -9,24 +9,31 @@ describe Gitlab::Git::Hook do
...
@@ -9,24 +9,31 @@ describe Gitlab::Git::Hook do
end
end
describe
"#trigger"
do
describe
"#trigger"
do
l
et
(
:project
)
{
create
(
:project
,
:repository
)
}
s
et
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:repository
)
{
project
.
repository
.
raw_repository
}
let
(
:repository
)
{
project
.
repository
.
raw_repository
}
let
(
:repo_path
)
{
repository
.
path
}
let
(
:repo_path
)
{
repository
.
path
}
let
(
:hooks_dir
)
{
File
.
join
(
repo_path
,
'hooks'
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:gl_id
)
{
Gitlab
::
GlId
.
gl_id
(
user
)
}
let
(
:gl_id
)
{
Gitlab
::
GlId
.
gl_id
(
user
)
}
let
(
:gl_username
)
{
user
.
username
}
let
(
:gl_username
)
{
user
.
username
}
def
create_hook
(
name
)
def
create_hook
(
name
)
FileUtils
.
mkdir_p
(
File
.
join
(
repo_path
,
'hooks'
))
FileUtils
.
mkdir_p
(
hooks_dir
)
File
.
open
(
File
.
join
(
repo_path
,
'hooks'
,
name
),
'w'
,
0755
)
do
|
f
|
hook_path
=
File
.
join
(
hooks_dir
,
name
)
f
.
write
(
'exit 0'
)
File
.
open
(
hook_path
,
'w'
,
0755
)
do
|
f
|
f
.
write
(
<<~
HOOK
)
#!/bin/sh
exit 0
HOOK
end
end
end
end
def
create_failing_hook
(
name
)
def
create_failing_hook
(
name
)
FileUtils
.
mkdir_p
(
File
.
join
(
repo_path
,
'hooks'
))
FileUtils
.
mkdir_p
(
hooks_dir
)
File
.
open
(
File
.
join
(
repo_path
,
'hooks'
,
name
),
'w'
,
0755
)
do
|
f
|
hook_path
=
File
.
join
(
hooks_dir
,
name
)
f
.
write
(
<<-
HOOK
)
File
.
open
(
hook_path
,
'w'
,
0755
)
do
|
f
|
f
.
write
(
<<~
HOOK
)
#!/bin/sh
echo 'regular message from the hook'
echo 'regular message from the hook'
echo 'error message from the hook' 1>&2
echo 'error message from the hook' 1>&2
echo 'error message from the hook line 2' 1>&2
echo 'error message from the hook line 2' 1>&2
...
@@ -38,7 +45,7 @@ describe Gitlab::Git::Hook do
...
@@ -38,7 +45,7 @@ describe Gitlab::Git::Hook do
[
'pre-receive'
,
'post-receive'
,
'update'
].
each
do
|
hook_name
|
[
'pre-receive'
,
'post-receive'
,
'update'
].
each
do
|
hook_name
|
context
"when triggering a
#{
hook_name
}
hook"
do
context
"when triggering a
#{
hook_name
}
hook"
do
context
"when the hook is successful"
do
context
"when the hook is successful"
do
let
(
:hook_path
)
{
File
.
join
(
repo_path
,
'hooks'
,
hook_name
)
}
let
(
:hook_path
)
{
File
.
join
(
hooks_dir
,
hook_name
)
}
let
(
:gl_repository
)
{
Gitlab
::
GlRepository
.
gl_repository
(
project
,
false
)
}
let
(
:gl_repository
)
{
Gitlab
::
GlRepository
.
gl_repository
(
project
,
false
)
}
let
(
:env
)
do
let
(
:env
)
do
{
{
...
@@ -76,7 +83,7 @@ describe Gitlab::Git::Hook do
...
@@ -76,7 +83,7 @@ describe Gitlab::Git::Hook do
status
,
errors
=
hook
.
trigger
(
gl_id
,
gl_username
,
blank
,
blank
,
ref
)
status
,
errors
=
hook
.
trigger
(
gl_id
,
gl_username
,
blank
,
blank
,
ref
)
expect
(
status
).
to
be
false
expect
(
status
).
to
be
false
expect
(
errors
).
to
eq
(
"error message from the hook
<br>error message from the hook line 2<br>
"
)
expect
(
errors
).
to
eq
(
"error message from the hook
\n
error message from the hook line 2
\n
"
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/git/hooks_service_spec.rb
View file @
ea8dc107
...
@@ -26,24 +26,24 @@ describe Gitlab::Git::HooksService, seed_helper: true do
...
@@ -26,24 +26,24 @@ describe Gitlab::Git::HooksService, seed_helper: true do
context
'when pre-receive hook failed'
do
context
'when pre-receive hook failed'
do
it
'does not call post-receive hook'
do
it
'does not call post-receive hook'
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
,
'
hello world
'
])
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
do
expect
do
service
.
execute
(
user
,
repository
,
blankrev
,
newrev
,
ref
)
service
.
execute
(
user
,
repository
,
blankrev
,
newrev
,
ref
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
PreReceiveError
,
'hello world'
)
end
end
end
end
context
'when update hook failed'
do
context
'when update hook failed'
do
it
'does not call post-receive hook'
do
it
'does not call post-receive hook'
do
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'pre-receive'
).
and_return
([
true
,
nil
])
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'pre-receive'
).
and_return
([
true
,
nil
])
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'update'
).
and_return
([
false
,
''
])
expect
(
service
).
to
receive
(
:run_hook
).
with
(
'update'
).
and_return
([
false
,
'
hello world
'
])
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
(
service
).
not_to
receive
(
:run_hook
).
with
(
'post-receive'
)
expect
do
expect
do
service
.
execute
(
user
,
repository
,
blankrev
,
newrev
,
ref
)
service
.
execute
(
user
,
repository
,
blankrev
,
newrev
,
ref
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
PreReceiveError
,
'hello world'
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/git/pre_receive_error_spec.rb
0 → 100644
View file @
ea8dc107
require
'spec_helper'
describe
Gitlab
::
Git
::
PreReceiveError
do
it
'makes its message HTML-friendly'
do
ex
=
described_class
.
new
(
"hello
\n
world
\n
"
)
expect
(
ex
.
message
).
to
eq
(
'hello<br>world<br>'
)
end
end
spec/lib/gitlab/gitaly_client/operation_service_spec.rb
View file @
ea8dc107
...
@@ -48,7 +48,7 @@ describe Gitlab::GitalyClient::OperationService do
...
@@ -48,7 +48,7 @@ describe Gitlab::GitalyClient::OperationService do
.
and_return
(
response
)
.
and_return
(
response
)
expect
{
subject
}.
to
raise_error
(
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
"something failed"
)
Gitlab
::
Git
::
PreReceiveError
,
"something failed"
)
end
end
end
end
end
end
...
@@ -85,7 +85,7 @@ describe Gitlab::GitalyClient::OperationService do
...
@@ -85,7 +85,7 @@ describe Gitlab::GitalyClient::OperationService do
.
and_return
(
response
)
.
and_return
(
response
)
expect
{
subject
}.
to
raise_error
(
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
"something failed"
)
Gitlab
::
Git
::
PreReceiveError
,
"something failed"
)
end
end
end
end
end
end
...
...
spec/models/repository_spec.rb
View file @
ea8dc107
...
@@ -1195,7 +1195,7 @@ describe Repository do
...
@@ -1195,7 +1195,7 @@ describe Repository do
Gitlab
::
Git
::
OperationService
.
new
(
git_user
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Gitlab
::
Git
::
OperationService
.
new
(
git_user
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
new_rev
new_rev
end
end
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
PreReceiveError
)
end
end
end
end
...
@@ -1938,13 +1938,13 @@ describe Repository do
...
@@ -1938,13 +1938,13 @@ describe Repository do
context
'when pre hooks failed'
do
context
'when pre hooks failed'
do
before
do
before
do
allow_any_instance_of
(
Gitlab
::
GitalyClient
::
OperationService
)
allow_any_instance_of
(
Gitlab
::
GitalyClient
::
OperationService
)
.
to
receive
(
:user_delete_branch
).
and_raise
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
.
to
receive
(
:user_delete_branch
).
and_raise
(
Gitlab
::
Git
::
PreReceiveError
)
end
end
it
'gets an error and does not delete the branch'
do
it
'gets an error and does not delete the branch'
do
expect
do
expect
do
repository
.
rm_branch
(
user
,
'feature'
)
repository
.
rm_branch
(
user
,
'feature'
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
PreReceiveError
)
expect
(
repository
.
find_branch
(
'feature'
)).
not_to
be_nil
expect
(
repository
.
find_branch
(
'feature'
)).
not_to
be_nil
end
end
...
@@ -1980,7 +1980,7 @@ describe Repository do
...
@@ -1980,7 +1980,7 @@ describe Repository do
expect
do
expect
do
repository
.
rm_branch
(
user
,
'feature'
)
repository
.
rm_branch
(
user
,
'feature'
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
PreReceiveError
)
end
end
it
'does not delete the branch'
do
it
'does not delete the branch'
do
...
@@ -1988,7 +1988,7 @@ describe Repository do
...
@@ -1988,7 +1988,7 @@ describe Repository do
expect
do
expect
do
repository
.
rm_branch
(
user
,
'feature'
)
repository
.
rm_branch
(
user
,
'feature'
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
PreReceiveError
)
expect
(
repository
.
find_branch
(
'feature'
)).
not_to
be_nil
expect
(
repository
.
find_branch
(
'feature'
)).
not_to
be_nil
end
end
end
end
...
...
spec/services/merge_requests/ff_merge_service_spec.rb
View file @
ea8dc107
...
@@ -72,7 +72,7 @@ describe MergeRequests::FfMergeService do
...
@@ -72,7 +72,7 @@ describe MergeRequests::FfMergeService do
it
'logs and saves error if there is an PreReceiveError exception'
do
it
'logs and saves error if there is an PreReceiveError exception'
do
error_message
=
'error message'
error_message
=
'error message'
allow
(
service
).
to
receive
(
:repository
).
and_raise
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
error_message
)
allow
(
service
).
to
receive
(
:repository
).
and_raise
(
Gitlab
::
Git
::
PreReceiveError
,
error_message
)
allow
(
service
).
to
receive
(
:execute_hooks
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
merge_request
)
service
.
execute
(
merge_request
)
...
...
spec/services/merge_requests/merge_service_spec.rb
View file @
ea8dc107
...
@@ -226,7 +226,7 @@ describe MergeRequests::MergeService do
...
@@ -226,7 +226,7 @@ describe MergeRequests::MergeService do
it
'logs and saves error if there is an PreReceiveError exception'
do
it
'logs and saves error if there is an PreReceiveError exception'
do
error_message
=
'error message'
error_message
=
'error message'
allow
(
service
).
to
receive
(
:repository
).
and_raise
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
error_message
)
allow
(
service
).
to
receive
(
:repository
).
and_raise
(
Gitlab
::
Git
::
PreReceiveError
,
error_message
)
allow
(
service
).
to
receive
(
:execute_hooks
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
merge_request
)
service
.
execute
(
merge_request
)
...
...
spec/services/tags/create_service_spec.rb
View file @
ea8dc107
...
@@ -41,7 +41,7 @@ describe Tags::CreateService do
...
@@ -41,7 +41,7 @@ describe Tags::CreateService do
it
'returns an error'
do
it
'returns an error'
do
expect
(
repository
).
to
receive
(
:add_tag
)
expect
(
repository
).
to
receive
(
:add_tag
)
.
with
(
user
,
'v1.1.0'
,
'master'
,
'Foo'
)
.
with
(
user
,
'v1.1.0'
,
'master'
,
'Foo'
)
.
and_raise
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
,
'something went wrong'
)
.
and_raise
(
Gitlab
::
Git
::
PreReceiveError
,
'something went wrong'
)
response
=
service
.
execute
(
'v1.1.0'
,
'master'
,
'Foo'
)
response
=
service
.
execute
(
'v1.1.0'
,
'master'
,
'Foo'
)
...
...
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