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
9e40baba
Commit
9e40baba
authored
Sep 13, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Gitlab::Git::Committer to User
parent
1f5ae8cd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
39 deletions
+45
-39
app/models/repository.rb
app/models/repository.rb
+4
-4
lib/gitlab/git/operation_service.rb
lib/gitlab/git/operation_service.rb
+7
-5
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+10
-10
lib/gitlab/git/user.rb
lib/gitlab/git/user.rb
+7
-3
spec/lib/gitlab/git/hooks_service_spec.rb
spec/lib/gitlab/git/hooks_service_spec.rb
+4
-4
spec/lib/gitlab/git/user_spec.rb
spec/lib/gitlab/git/user_spec.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+12
-12
No files found.
app/models/repository.rb
View file @
9e40baba
...
@@ -166,7 +166,7 @@ class Repository
...
@@ -166,7 +166,7 @@ class Repository
end
end
def
add_branch
(
user
,
branch_name
,
ref
)
def
add_branch
(
user
,
branch_name
,
ref
)
branch
=
raw_repository
.
add_branch
(
branch_name
,
committ
er:
user
,
target:
ref
)
branch
=
raw_repository
.
add_branch
(
branch_name
,
us
er:
user
,
target:
ref
)
after_create_branch
after_create_branch
...
@@ -176,7 +176,7 @@ class Repository
...
@@ -176,7 +176,7 @@ class Repository
end
end
def
add_tag
(
user
,
tag_name
,
target
,
message
=
nil
)
def
add_tag
(
user
,
tag_name
,
target
,
message
=
nil
)
raw_repository
.
add_tag
(
tag_name
,
committ
er:
user
,
target:
target
,
message:
message
)
raw_repository
.
add_tag
(
tag_name
,
us
er:
user
,
target:
target
,
message:
message
)
rescue
Gitlab
::
Git
::
Repository
::
InvalidRef
rescue
Gitlab
::
Git
::
Repository
::
InvalidRef
false
false
end
end
...
@@ -184,7 +184,7 @@ class Repository
...
@@ -184,7 +184,7 @@ class Repository
def
rm_branch
(
user
,
branch_name
)
def
rm_branch
(
user
,
branch_name
)
before_remove_branch
before_remove_branch
raw_repository
.
rm_branch
(
branch_name
,
committ
er:
user
)
raw_repository
.
rm_branch
(
branch_name
,
us
er:
user
)
after_remove_branch
after_remove_branch
true
true
...
@@ -193,7 +193,7 @@ class Repository
...
@@ -193,7 +193,7 @@ class Repository
def
rm_tag
(
user
,
tag_name
)
def
rm_tag
(
user
,
tag_name
)
before_remove_tag
before_remove_tag
raw_repository
.
rm_tag
(
tag_name
,
committ
er:
user
)
raw_repository
.
rm_tag
(
tag_name
,
us
er:
user
)
after_remove_tag
after_remove_tag
true
true
...
...
lib/gitlab/git/operation_service.rb
View file @
9e40baba
module
Gitlab
module
Gitlab
module
Git
module
Git
class
OperationService
class
OperationService
attr_reader
:
committ
er
,
:repository
attr_reader
:
us
er
,
:repository
def
initialize
(
committer
,
new_repository
)
def
initialize
(
user
,
new_repository
)
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
committer
)
if
committer
.
is_a?
(
User
)
if
user
@committer
=
committer
user
=
Gitlab
::
Git
::
User
.
from_gitlab
(
user
)
unless
user
.
respond_to?
(
:gl_id
)
@user
=
user
end
# Refactoring aid
# Refactoring aid
unless
new_repository
.
is_a?
(
Gitlab
::
Git
::
Repository
)
unless
new_repository
.
is_a?
(
Gitlab
::
Git
::
Repository
)
...
@@ -128,7 +130,7 @@ module Gitlab
...
@@ -128,7 +130,7 @@ module Gitlab
def
with_hooks
(
ref
,
newrev
,
oldrev
)
def
with_hooks
(
ref
,
newrev
,
oldrev
)
Gitlab
::
Git
::
HooksService
.
new
.
execute
(
Gitlab
::
Git
::
HooksService
.
new
.
execute
(
committ
er
,
us
er
,
repository
,
repository
,
oldrev
,
oldrev
,
newrev
,
newrev
,
...
...
lib/gitlab/git/repository.rb
View file @
9e40baba
...
@@ -610,43 +610,43 @@ module Gitlab
...
@@ -610,43 +610,43 @@ module Gitlab
# TODO: implement this method
# TODO: implement this method
end
end
def
add_branch
(
branch_name
,
committ
er
:,
target
:)
def
add_branch
(
branch_name
,
us
er
:,
target
:)
target_object
=
Ref
.
dereference_object
(
lookup
(
target
))
target_object
=
Ref
.
dereference_object
(
lookup
(
target
))
raise
InvalidRef
.
new
(
"target not found:
#{
target
}
"
)
unless
target_object
raise
InvalidRef
.
new
(
"target not found:
#{
target
}
"
)
unless
target_object
OperationService
.
new
(
committ
er
,
self
).
add_branch
(
branch_name
,
target_object
.
oid
)
OperationService
.
new
(
us
er
,
self
).
add_branch
(
branch_name
,
target_object
.
oid
)
find_branch
(
branch_name
)
find_branch
(
branch_name
)
rescue
Rugged
::
ReferenceError
=>
ex
rescue
Rugged
::
ReferenceError
=>
ex
raise
InvalidRef
,
ex
raise
InvalidRef
,
ex
end
end
def
add_tag
(
tag_name
,
committ
er
:,
target
:,
message:
nil
)
def
add_tag
(
tag_name
,
us
er
:,
target
:,
message:
nil
)
target_object
=
Ref
.
dereference_object
(
lookup
(
target
))
target_object
=
Ref
.
dereference_object
(
lookup
(
target
))
raise
InvalidRef
.
new
(
"target not found:
#{
target
}
"
)
unless
target_object
raise
InvalidRef
.
new
(
"target not found:
#{
target
}
"
)
unless
target_object
committer
=
Committer
.
from_user
(
committer
)
if
committer
.
is_a?
(
User
)
user
=
Gitlab
::
Git
::
User
.
from_gitlab
(
user
)
unless
user
.
respond_to?
(
:gl_id
)
options
=
nil
# Use nil, not the empty hash. Rugged cares about this.
options
=
nil
# Use nil, not the empty hash. Rugged cares about this.
if
message
if
message
options
=
{
options
=
{
message:
message
,
message:
message
,
tagger:
Gitlab
::
Git
.
committer_hash
(
email:
committer
.
email
,
name:
committ
er
.
name
)
tagger:
Gitlab
::
Git
.
committer_hash
(
email:
user
.
email
,
name:
us
er
.
name
)
}
}
end
end
OperationService
.
new
(
committ
er
,
self
).
add_tag
(
tag_name
,
target_object
.
oid
,
options
)
OperationService
.
new
(
us
er
,
self
).
add_tag
(
tag_name
,
target_object
.
oid
,
options
)
find_tag
(
tag_name
)
find_tag
(
tag_name
)
rescue
Rugged
::
ReferenceError
=>
ex
rescue
Rugged
::
ReferenceError
=>
ex
raise
InvalidRef
,
ex
raise
InvalidRef
,
ex
end
end
def
rm_branch
(
branch_name
,
committ
er
:)
def
rm_branch
(
branch_name
,
us
er
:)
OperationService
.
new
(
committ
er
,
self
).
rm_branch
(
find_branch
(
branch_name
))
OperationService
.
new
(
us
er
,
self
).
rm_branch
(
find_branch
(
branch_name
))
end
end
def
rm_tag
(
tag_name
,
committ
er
:)
def
rm_tag
(
tag_name
,
us
er
:)
OperationService
.
new
(
committ
er
,
self
).
rm_tag
(
find_tag
(
tag_name
))
OperationService
.
new
(
us
er
,
self
).
rm_tag
(
find_tag
(
tag_name
))
end
end
def
find_tag
(
name
)
def
find_tag
(
name
)
...
...
lib/gitlab/git/
committ
er.rb
→
lib/gitlab/git/
us
er.rb
View file @
9e40baba
module
Gitlab
module
Gitlab
module
Git
module
Git
class
Committ
er
class
Us
er
attr_reader
:name
,
:email
,
:gl_id
attr_reader
:name
,
:email
,
:gl_id
def
self
.
from_user
(
user
)
def
self
.
from_gitlab
(
gitlab_user
)
new
(
user
.
name
,
user
.
email
,
Gitlab
::
GlId
.
gl_id
(
user
))
new
(
gitlab_user
.
name
,
gitlab_user
.
email
,
Gitlab
::
GlId
.
gl_id
(
gitlab_user
))
end
def
self
.
from_gitaly
(
gitaly_user
)
new
(
gitaly_user
.
name
,
gitaly_user
.
email
,
gitaly_user
.
gl_id
)
end
end
def
initialize
(
name
,
email
,
gl_id
)
def
initialize
(
name
,
email
,
gl_id
)
...
...
spec/lib/gitlab/git/hooks_service_spec.rb
View file @
9e40baba
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Git
::
HooksService
,
seed_helper:
true
do
describe
Gitlab
::
Git
::
HooksService
,
seed_helper:
true
do
let
(
:
committer
)
{
Gitlab
::
Git
::
Committ
er
.
new
(
'Jane Doe'
,
'janedoe@example.com'
,
'user-456'
)
}
let
(
:
user
)
{
Gitlab
::
Git
::
Us
er
.
new
(
'Jane Doe'
,
'janedoe@example.com'
,
'user-456'
)
}
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
,
'project-123'
)
}
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
,
'project-123'
)
}
let
(
:service
)
{
described_class
.
new
}
let
(
:service
)
{
described_class
.
new
}
...
@@ -18,7 +18,7 @@ describe Gitlab::Git::HooksService, seed_helper: true do
...
@@ -18,7 +18,7 @@ describe Gitlab::Git::HooksService, seed_helper: true do
hook
=
double
(
trigger:
[
true
,
nil
])
hook
=
double
(
trigger:
[
true
,
nil
])
expect
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:new
).
exactly
(
3
).
times
.
and_return
(
hook
)
expect
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:new
).
exactly
(
3
).
times
.
and_return
(
hook
)
service
.
execute
(
committ
er
,
repository
,
@blankrev
,
@newrev
,
@ref
)
{
}
service
.
execute
(
us
er
,
repository
,
@blankrev
,
@newrev
,
@ref
)
{
}
end
end
end
end
...
@@ -28,7 +28,7 @@ describe Gitlab::Git::HooksService, seed_helper: true do
...
@@ -28,7 +28,7 @@ describe Gitlab::Git::HooksService, seed_helper: true do
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
(
committ
er
,
repository
,
@blankrev
,
@newrev
,
@ref
)
service
.
execute
(
us
er
,
repository
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
end
end
...
@@ -40,7 +40,7 @@ describe Gitlab::Git::HooksService, seed_helper: true do
...
@@ -40,7 +40,7 @@ describe Gitlab::Git::HooksService, seed_helper: true do
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
(
committ
er
,
repository
,
@blankrev
,
@newrev
,
@ref
)
service
.
execute
(
us
er
,
repository
,
@blankrev
,
@newrev
,
@ref
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
end
end
end
end
...
...
spec/lib/gitlab/git/
committ
er_spec.rb
→
spec/lib/gitlab/git/
us
er_spec.rb
View file @
9e40baba
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Git
::
Committ
er
do
describe
Gitlab
::
Git
::
Us
er
do
let
(
:name
)
{
'Jane Doe'
}
let
(
:name
)
{
'Jane Doe'
}
let
(
:email
)
{
'janedoe@example.com'
}
let
(
:email
)
{
'janedoe@example.com'
}
let
(
:gl_id
)
{
'user-123'
}
let
(
:gl_id
)
{
'user-123'
}
...
...
spec/models/repository_spec.rb
View file @
9e40baba
...
@@ -8,7 +8,7 @@ describe Repository, models: true do
...
@@ -8,7 +8,7 @@ describe Repository, models: true do
let
(
:repository
)
{
project
.
repository
}
let
(
:repository
)
{
project
.
repository
}
let
(
:broken_repository
)
{
create
(
:project
,
:broken_storage
).
repository
}
let
(
:broken_repository
)
{
create
(
:project
,
:broken_storage
).
repository
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:
committer
)
{
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
}
let
(
:
git_user
)
{
Gitlab
::
Git
::
User
.
from_gitlab
(
user
)
}
let
(
:commit_options
)
do
let
(
:commit_options
)
do
author
=
repository
.
user_to_committer
(
user
)
author
=
repository
.
user_to_committer
(
user
)
...
@@ -886,7 +886,7 @@ describe Repository, models: true do
...
@@ -886,7 +886,7 @@ describe Repository, models: true do
context
'when pre hooks were successful'
do
context
'when pre hooks were successful'
do
it
'runs without errors'
do
it
'runs without errors'
do
expect_any_instance_of
(
Gitlab
::
Git
::
HooksService
).
to
receive
(
:execute
)
expect_any_instance_of
(
Gitlab
::
Git
::
HooksService
).
to
receive
(
:execute
)
.
with
(
committ
er
,
repository
.
raw_repository
,
old_rev
,
blank_sha
,
'refs/heads/feature'
)
.
with
(
git_us
er
,
repository
.
raw_repository
,
old_rev
,
blank_sha
,
'refs/heads/feature'
)
expect
{
repository
.
rm_branch
(
user
,
'feature'
)
}.
not_to
raise_error
expect
{
repository
.
rm_branch
(
user
,
'feature'
)
}.
not_to
raise_error
end
end
...
@@ -932,20 +932,20 @@ describe Repository, models: true do
...
@@ -932,20 +932,20 @@ describe Repository, models: true do
service
=
Gitlab
::
Git
::
HooksService
.
new
service
=
Gitlab
::
Git
::
HooksService
.
new
expect
(
Gitlab
::
Git
::
HooksService
).
to
receive
(
:new
).
and_return
(
service
)
expect
(
Gitlab
::
Git
::
HooksService
).
to
receive
(
:new
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
expect
(
service
).
to
receive
(
:execute
)
.
with
(
committ
er
,
target_repository
.
raw_repository
,
old_rev
,
new_rev
,
updating_ref
)
.
with
(
git_us
er
,
target_repository
.
raw_repository
,
old_rev
,
new_rev
,
updating_ref
)
.
and_yield
(
service
).
and_return
(
true
)
.
and_yield
(
service
).
and_return
(
true
)
end
end
it
'runs without errors'
do
it
'runs without errors'
do
expect
do
expect
do
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
new_rev
new_rev
end
end
end
.
not_to
raise_error
end
.
not_to
raise_error
end
end
it
'ensures the autocrlf Git option is set to :input'
do
it
'ensures the autocrlf Git option is set to :input'
do
service
=
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
repository
.
raw_repository
)
service
=
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
repository
.
raw_repository
)
expect
(
service
).
to
receive
(
:update_autocrlf_option
)
expect
(
service
).
to
receive
(
:update_autocrlf_option
)
...
@@ -956,7 +956,7 @@ describe Repository, models: true do
...
@@ -956,7 +956,7 @@ describe Repository, models: true do
it
'updates the head'
do
it
'updates the head'
do
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
old_rev
)
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
old_rev
)
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
new_rev
new_rev
end
end
...
@@ -974,7 +974,7 @@ describe Repository, models: true do
...
@@ -974,7 +974,7 @@ describe Repository, models: true do
expect
(
target_project
.
repository
.
raw_repository
).
to
receive
(
:fetch_ref
)
expect
(
target_project
.
repository
.
raw_repository
).
to
receive
(
:fetch_ref
)
.
and_call_original
.
and_call_original
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
target_repository
.
raw_repository
)
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
target_repository
.
raw_repository
)
.
with_branch
(
.
with_branch
(
'master'
,
'master'
,
start_repository:
project
.
repository
.
raw_repository
,
start_repository:
project
.
repository
.
raw_repository
,
...
@@ -990,7 +990,7 @@ describe Repository, models: true do
...
@@ -990,7 +990,7 @@ describe Repository, models: true do
it
'does not fetch_ref and just pass the commit'
do
it
'does not fetch_ref and just pass the commit'
do
expect
(
target_repository
).
not_to
receive
(
:fetch_ref
)
expect
(
target_repository
).
not_to
receive
(
:fetch_ref
)
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
target_repository
.
raw_repository
)
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
target_repository
.
raw_repository
)
.
with_branch
(
'feature'
,
start_repository:
project
.
repository
.
raw_repository
)
{
new_rev
}
.
with_branch
(
'feature'
,
start_repository:
project
.
repository
.
raw_repository
)
{
new_rev
}
end
end
end
end
...
@@ -1009,7 +1009,7 @@ describe Repository, models: true do
...
@@ -1009,7 +1009,7 @@ describe Repository, models: true do
end
end
expect
do
expect
do
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
target_project
.
repository
.
raw_repository
)
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
target_project
.
repository
.
raw_repository
)
.
with_branch
(
'feature'
,
.
with_branch
(
'feature'
,
start_repository:
project
.
repository
.
raw_repository
,
start_repository:
project
.
repository
.
raw_repository
,
&
:itself
)
&
:itself
)
...
@@ -1031,7 +1031,7 @@ describe Repository, models: true do
...
@@ -1031,7 +1031,7 @@ describe Repository, models: true do
repository
.
add_branch
(
user
,
branch
,
old_rev
)
repository
.
add_branch
(
user
,
branch
,
old_rev
)
expect
do
expect
do
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
new_rev
new_rev
end
end
end
.
not_to
raise_error
end
.
not_to
raise_error
...
@@ -1049,7 +1049,7 @@ describe Repository, models: true do
...
@@ -1049,7 +1049,7 @@ describe Repository, models: true do
# Updating 'master' to new_rev would lose the commits on 'master' that
# Updating 'master' to new_rev would lose the commits on 'master' that
# are not contained in new_rev. This should not be allowed.
# are not contained in new_rev. This should not be allowed.
expect
do
expect
do
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
new_rev
new_rev
end
end
end
.
to
raise_error
(
Gitlab
::
Git
::
CommitError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
CommitError
)
...
@@ -1061,7 +1061,7 @@ describe Repository, models: true do
...
@@ -1061,7 +1061,7 @@ describe Repository, models: true 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
,
''
])
expect
do
expect
do
Gitlab
::
Git
::
OperationService
.
new
(
committ
er
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Gitlab
::
Git
::
OperationService
.
new
(
git_us
er
,
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
::
HooksService
::
PreReceiveError
)
...
...
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