BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d03c605b
Commit
d03c605b
authored
Dec 14, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unify parameters and callback after hooks
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_19747856
parent
46d752ce
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
24 deletions
+21
-24
git_operation_service.rb
app/services/git_operation_service.rb
+16
-18
git.rb
lib/gitlab/git.rb
+1
-1
repository_spec.rb
spec/models/repository_spec.rb
+3
-4
git_garbage_collect_worker_spec.rb
spec/workers/git_garbage_collect_worker_spec.rb
+1
-1
No files found.
app/services/git_operation_service.rb
View file @
d03c605b
...
...
@@ -11,7 +11,7 @@ class GitOperationService
ref
=
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
branch_name
oldrev
=
Gitlab
::
Git
::
BLANK_SHA
with_hooks_and_update_ref
(
ref
,
oldrev
,
new
rev
)
update_ref_in_hooks
(
ref
,
newrev
,
old
rev
)
end
def
rm_branch
(
branch
)
...
...
@@ -19,14 +19,14 @@ class GitOperationService
oldrev
=
branch
.
dereferenced_target
.
id
newrev
=
Gitlab
::
Git
::
BLANK_SHA
with_hooks_and_update_ref
(
ref
,
oldrev
,
new
rev
)
update_ref_in_hooks
(
ref
,
newrev
,
old
rev
)
end
def
add_tag
(
tag_name
,
newrev
,
options
=
{})
ref
=
Gitlab
::
Git
::
TAG_REF_PREFIX
+
tag_name
oldrev
=
Gitlab
::
Git
::
BLANK_SHA
with_hooks
(
ref
,
oldrev
,
new
rev
)
do
|
service
|
with_hooks
(
ref
,
newrev
,
old
rev
)
do
|
service
|
raw_tag
=
repository
.
rugged
.
tags
.
create
(
tag_name
,
newrev
,
options
)
service
.
newrev
=
raw_tag
.
target_id
end
...
...
@@ -82,25 +82,23 @@ class GitOperationService
end
ref
=
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
branch_name
with_hooks_and_update_ref
(
ref
,
oldrev
,
newrev
)
do
# If repo was empty expire cache
repository
.
after_create
if
was_empty
repository
.
after_create_branch
if
was_empty
||
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
end
update_ref_in_hooks
(
ref
,
newrev
,
oldrev
)
# If repo was empty expire cache
repository
.
after_create
if
was_empty
repository
.
after_create_branch
if
was_empty
||
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
newrev
end
def
with_hooks_and_update_ref
(
ref
,
oldrev
,
newrev
)
with_hooks
(
ref
,
oldrev
,
newrev
)
do
|
service
|
update_ref!
(
ref
,
newrev
,
oldrev
)
yield
(
service
)
if
block_given?
def
update_ref_in_hooks
(
ref
,
newrev
,
oldrev
)
with_hooks
(
ref
,
newrev
,
oldrev
)
do
update_ref
(
ref
,
newrev
,
oldrev
)
end
end
def
with_hooks
(
ref
,
oldrev
,
new
rev
)
def
with_hooks
(
ref
,
newrev
,
old
rev
)
result
=
nil
GitHooksService
.
new
.
execute
(
...
...
@@ -116,7 +114,7 @@ class GitOperationService
result
end
def
update_ref
!
(
name
,
newrev
,
oldrev
)
def
update_ref
(
ref
,
newrev
,
oldrev
)
# We use 'git update-ref' because libgit2/rugged currently does not
# offer 'compare and swap' ref updates. Without compare-and-swap we can
# (and have!) accidentally reset the ref to an earlier state, clobbering
...
...
@@ -125,12 +123,12 @@ class GitOperationService
_
,
status
=
Gitlab
::
Popen
.
popen
(
command
,
repository
.
path_to_repo
)
do
|
stdin
|
stdin
.
write
(
"update
#{
name
}
\x00
#{
newrev
}
\x00
#{
oldrev
}
\x00
"
)
stdin
.
write
(
"update
#{
ref
}
\x00
#{
newrev
}
\x00
#{
oldrev
}
\x00
"
)
end
unless
status
.
zero?
raise
Repository
::
CommitError
.
new
(
"Could not update branch
#{
name
.
sub
(
'refs/heads/'
,
''
)
}
."
\
"Could not update branch
#{
Gitlab
::
Git
.
branch_name
(
ref
)
}
."
\
" Please refresh and try again."
)
end
end
...
...
lib/gitlab/git.rb
View file @
d03c605b
...
...
@@ -6,7 +6,7 @@ module Gitlab
class
<<
self
def
ref_name
(
ref
)
ref
.
g
sub
(
/\Arefs\/(tags|heads)\//
,
''
)
ref
.
sub
(
/\Arefs\/(tags|heads)\//
,
''
)
end
def
branch_name
(
ref
)
...
...
spec/models/repository_spec.rb
View file @
d03c605b
...
...
@@ -829,7 +829,6 @@ describe Repository, models: true do
context
'when target branch is different from source branch'
do
before
do
allow_any_instance_of
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:trigger
).
and_return
([
true
,
''
])
allow
(
repository
).
to
receive
(
:update_ref!
)
end
it
'expires branch cache'
do
...
...
@@ -1474,16 +1473,16 @@ describe Repository, models: true do
end
end
describe
'#update_ref
!
'
do
describe
'#update_ref'
do
it
'can create a ref'
do
GitOperationService
.
new
(
nil
,
repository
).
send
(
:update_ref
!
,
'refs/heads/foobar'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
GitOperationService
.
new
(
nil
,
repository
).
send
(
:update_ref
,
'refs/heads/foobar'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
expect
(
repository
.
find_branch
(
'foobar'
)).
not_to
be_nil
end
it
'raises CommitError when the ref update fails'
do
expect
do
GitOperationService
.
new
(
nil
,
repository
).
send
(
:update_ref
!
,
'refs/heads/master'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
GitOperationService
.
new
(
nil
,
repository
).
send
(
:update_ref
,
'refs/heads/master'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
end
.
to
raise_error
(
Repository
::
CommitError
)
end
end
...
...
spec/workers/git_garbage_collect_worker_spec.rb
View file @
d03c605b
...
...
@@ -108,7 +108,7 @@ describe GitGarbageCollectWorker do
parents:
[
old_commit
],
)
GitOperationService
.
new
(
nil
,
project
.
repository
).
send
(
:update_ref
!
,
:update_ref
,
"refs/heads/
#{
SecureRandom
.
hex
(
6
)
}
"
,
new_commit_sha
,
Gitlab
::
Git
::
BLANK_SHA
...
...
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