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
c8614cbb
Commit
c8614cbb
authored
Aug 13, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Capture pre-receive exception
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
34690142
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
7 deletions
+19
-7
app/services/commit_service.rb
app/services/commit_service.rb
+18
-6
app/services/files/base_service.rb
app/services/files/base_service.rb
+1
-1
No files found.
app/services/commit_service.rb
View file @
c8614cbb
require
'securerandom'
require
'securerandom'
class
CommitService
class
CommitService
class
PreReceiveError
<
StandardError
;
end
class
CommitError
<
StandardError
;
end
def
self
.
transaction
(
project
,
current_user
,
ref
)
def
self
.
transaction
(
project
,
current_user
,
ref
)
repository
=
project
.
repository
repository
=
project
.
repository
path_to_repo
=
repository
.
path_to_repo
path_to_repo
=
repository
.
path_to_repo
empty_repo
=
repository
.
empty?
# Create temporary ref
# Create temporary ref
random_string
=
SecureRandom
.
hex
random_string
=
SecureRandom
.
hex
tmp_ref
=
"refs/tmp/
#{
random_string
}
/head"
tmp_ref
=
"refs/tmp/
#{
random_string
}
/head"
unless
empty_repo
target
=
repository
.
find_branch
(
ref
).
target
target
=
repository
.
find_branch
(
ref
).
target
repository
.
rugged
.
references
.
create
(
tmp_ref
,
target
)
repository
.
rugged
.
references
.
create
(
tmp_ref
,
target
)
end
# Make commit in tmp ref
# Make commit in tmp ref
sha
=
yield
(
tmp_ref
)
sha
=
yield
(
tmp_ref
)
unless
sha
unless
sha
raise
'Failed to create commit'
raise
CommitError
.
new
(
'Failed to create commit'
)
end
end
# Run GitLab pre-receive hook
# Run GitLab pre-receive hook
status
=
PreCommitService
.
new
(
project
,
current_user
).
execute
(
sha
,
ref
)
status
=
PreCommitService
.
new
(
project
,
current_user
).
execute
(
sha
,
ref
)
if
status
if
status
if
empty_repo
# Create branch
repository
.
rugged
.
references
.
create
(
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
,
sha
)
else
# Update head
# Update head
repository
.
rugged
.
references
.
update
(
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
,
sha
)
repository
.
rugged
.
references
.
update
(
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
,
sha
)
end
# Run GitLab post receive hook
# Run GitLab post receive hook
PostCommitService
.
new
(
project
,
current_user
).
execute
(
sha
,
ref
)
PostCommitService
.
new
(
project
,
current_user
).
execute
(
sha
,
ref
)
...
@@ -31,7 +43,7 @@ class CommitService
...
@@ -31,7 +43,7 @@ class CommitService
# Remove tmp ref and return error to user
# Remove tmp ref and return error to user
repository
.
rugged
.
references
.
delete
(
tmp_ref
)
repository
.
rugged
.
references
.
delete
(
tmp_ref
)
raise
'Commit was rejected by pre-reveive hook'
raise
PreReceiveError
.
new
(
'Commit was rejected by pre-reveive hook'
)
end
end
end
end
end
end
app/services/files/base_service.rb
View file @
c8614cbb
...
@@ -26,7 +26,7 @@ module Files
...
@@ -26,7 +26,7 @@ module Files
else
else
error
(
"Something went wrong. Your changes were not committed"
)
error
(
"Something went wrong. Your changes were not committed"
)
end
end
rescue
ValidationError
=>
ex
rescue
CommitService
::
CommitError
,
CommitService
::
PreReceiveError
,
ValidationError
=>
ex
error
(
ex
.
message
)
error
(
ex
.
message
)
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