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
4efdb451
Commit
4efdb451
authored
Sep 04, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'move-git-operation-service' into 'master'
Move GitOperationService to Gitlab::Git See merge request !13984
parents
25a443d6
6cdaa27a
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
32 deletions
+36
-32
repository.rb
app/models/repository.rb
+6
-7
create_service.rb
app/services/commits/create_service.rb
+1
-1
git.rb
lib/gitlab/git.rb
+1
-0
operation_service.rb
lib/gitlab/git/operation_service.rb
+8
-4
repository_spec.rb
spec/models/repository_spec.rb
+15
-15
files_spec.rb
spec/requests/api/files_spec.rb
+2
-2
files_spec.rb
spec/requests/api/v3/files_spec.rb
+2
-2
git_garbage_collect_worker_spec.rb
spec/workers/git_garbage_collect_worker_spec.rb
+1
-1
No files found.
app/models/repository.rb
View file @
4efdb451
...
...
@@ -20,7 +20,6 @@ class Repository
delegate
:ref_name_for_sha
,
to: :raw_repository
CommitError
=
Class
.
new
(
StandardError
)
CreateTreeError
=
Class
.
new
(
StandardError
)
# Methods that cache data from the Git repository.
...
...
@@ -171,7 +170,7 @@ class Repository
return
false
unless
newrev
GitOperationService
.
new
(
user
,
raw_repository
).
add_branch
(
branch_name
,
newrev
)
Git
lab
::
Git
::
OperationService
.
new
(
user
,
raw_repository
).
add_branch
(
branch_name
,
newrev
)
after_create_branch
find_branch
(
branch_name
)
...
...
@@ -183,7 +182,7 @@ class Repository
return
false
unless
newrev
GitOperationService
.
new
(
user
,
raw_repository
).
add_tag
(
tag_name
,
newrev
,
options
)
Git
lab
::
Git
::
OperationService
.
new
(
user
,
raw_repository
).
add_tag
(
tag_name
,
newrev
,
options
)
find_tag
(
tag_name
)
end
...
...
@@ -192,7 +191,7 @@ class Repository
before_remove_branch
branch
=
find_branch
(
branch_name
)
GitOperationService
.
new
(
user
,
raw_repository
).
rm_branch
(
branch
)
Git
lab
::
Git
::
OperationService
.
new
(
user
,
raw_repository
).
rm_branch
(
branch
)
after_remove_branch
true
...
...
@@ -202,7 +201,7 @@ class Repository
before_remove_tag
tag
=
find_tag
(
tag_name
)
GitOperationService
.
new
(
user
,
raw_repository
).
rm_tag
(
tag
)
Git
lab
::
Git
::
OperationService
.
new
(
user
,
raw_repository
).
rm_tag
(
tag
)
after_remove_tag
true
...
...
@@ -772,7 +771,7 @@ class Repository
end
def
with_branch
(
user
,
*
args
)
result
=
GitOperationService
.
new
(
user
,
raw_repository
).
with_branch
(
*
args
)
do
|
start_commit
|
result
=
Git
lab
::
Git
::
OperationService
.
new
(
user
,
raw_repository
).
with_branch
(
*
args
)
do
|
start_commit
|
yield
start_commit
end
...
...
@@ -868,7 +867,7 @@ class Repository
merge_request
.
update
(
in_progress_merge_commit_sha:
commit_id
)
commit_id
end
rescue
Repository
::
CommitError
# when merge_index.conflicts?
rescue
Gitlab
::
Git
::
CommitError
# when merge_index.conflicts?
false
end
...
...
app/services/commits/create_service.rb
View file @
4efdb451
...
...
@@ -17,7 +17,7 @@ module Commits
new_commit
=
create_commit!
success
(
result:
new_commit
)
rescue
ValidationError
,
ChangeError
,
Gitlab
::
Git
::
Index
::
IndexError
,
Repository
::
CommitError
,
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
rescue
ValidationError
,
ChangeError
,
Gitlab
::
Git
::
Index
::
IndexError
,
Gitlab
::
Git
::
CommitError
,
Gitlab
::
Git
::
HooksService
::
PreReceiveError
=>
ex
error
(
ex
.
message
)
end
...
...
lib/gitlab/git.rb
View file @
4efdb451
...
...
@@ -5,6 +5,7 @@ module Gitlab
BRANCH_REF_PREFIX
=
"refs/heads/"
.
freeze
CommandError
=
Class
.
new
(
StandardError
)
CommitError
=
Class
.
new
(
StandardError
)
class
<<
self
include
Gitlab
::
EncodingHelper
...
...
app/services/git_
operation_service.rb
→
lib/gitlab/git/
operation_service.rb
View file @
4efdb451
class
GitOperationService
module
Gitlab
module
Git
class
OperationService
attr_reader
:committer
,
:repository
def
initialize
(
committer
,
new_repository
)
...
...
@@ -94,7 +96,7 @@ class GitOperationService
newrev
=
yield
unless
newrev
raise
Repository
::
CommitError
.
new
(
'Failed to create commit'
)
raise
Gitlab
::
Git
::
CommitError
.
new
(
'Failed to create commit'
)
end
branch
=
repository
.
find_branch
(
branch_name
)
...
...
@@ -114,7 +116,7 @@ class GitOperationService
if
oldrev
==
repository
.
rugged
.
merge_base
(
newrev
,
branch
.
target
)
oldrev
else
raise
Repository
::
CommitError
.
new
(
'Branch diverged'
)
raise
Gitlab
::
Git
::
CommitError
.
new
(
'Branch diverged'
)
end
end
...
...
@@ -150,7 +152,7 @@ class GitOperationService
end
unless
status
.
zero?
raise
Repository
::
CommitError
.
new
(
raise
Gitlab
::
Git
::
CommitError
.
new
(
"Could not update branch
#{
Gitlab
::
Git
.
branch_name
(
ref
)
}
."
\
" Please refresh and try again."
)
end
...
...
@@ -161,4 +163,6 @@ class GitOperationService
repository
.
autocrlf
=
:input
end
end
end
end
end
spec/models/repository_spec.rb
View file @
4efdb451
...
...
@@ -938,14 +938,14 @@ describe Repository, models: true do
it
'runs without errors'
do
expect
do
GitOperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
new_rev
end
end
.
not_to
raise_error
end
it
'ensures the autocrlf Git option is set to :input'
do
service
=
GitOperationService
.
new
(
committer
,
repository
.
raw_repository
)
service
=
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
repository
.
raw_repository
)
expect
(
service
).
to
receive
(
:update_autocrlf_option
)
...
...
@@ -956,7 +956,7 @@ describe Repository, models: true do
it
'updates the head'
do
expect
(
repository
.
find_branch
(
'feature'
).
dereferenced_target
.
id
).
to
eq
(
old_rev
)
GitOperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
new_rev
end
...
...
@@ -974,7 +974,7 @@ describe Repository, models: true do
expect
(
target_project
.
repository
.
raw_repository
).
to
receive
(
:fetch_ref
)
.
and_call_original
GitOperationService
.
new
(
committer
,
target_repository
.
raw_repository
)
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
target_repository
.
raw_repository
)
.
with_branch
(
'master'
,
start_repository:
project
.
repository
.
raw_repository
,
...
...
@@ -990,7 +990,7 @@ describe Repository, models: true do
it
'does not fetch_ref and just pass the commit'
do
expect
(
target_repository
).
not_to
receive
(
:fetch_ref
)
GitOperationService
.
new
(
committer
,
target_repository
.
raw_repository
)
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
target_repository
.
raw_repository
)
.
with_branch
(
'feature'
,
start_repository:
project
.
repository
.
raw_repository
)
{
new_rev
}
end
end
...
...
@@ -1009,7 +1009,7 @@ describe Repository, models: true do
end
expect
do
GitOperationService
.
new
(
committer
,
target_project
.
repository
.
raw_repository
)
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
target_project
.
repository
.
raw_repository
)
.
with_branch
(
'feature'
,
start_repository:
project
.
repository
.
raw_repository
,
&
:itself
)
...
...
@@ -1031,7 +1031,7 @@ describe Repository, models: true do
repository
.
add_branch
(
user
,
branch
,
old_rev
)
expect
do
GitOperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
new_rev
end
end
.
not_to
raise_error
...
...
@@ -1049,10 +1049,10 @@ describe Repository, models: true do
# Updating 'master' to new_rev would lose the commits on 'master' that
# are not contained in new_rev. This should not be allowed.
expect
do
GitOperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
branch
)
do
new_rev
end
end
.
to
raise_error
(
Repository
::
CommitError
)
end
.
to
raise_error
(
Gitlab
::
Git
::
CommitError
)
end
end
...
...
@@ -1061,7 +1061,7 @@ describe Repository, models: true do
allow_any_instance_of
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:trigger
).
and_return
([
false
,
''
])
expect
do
GitOperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
Git
lab
::
Git
::
OperationService
.
new
(
committer
,
repository
.
raw_repository
).
with_branch
(
'feature'
)
do
new_rev
end
end
.
to
raise_error
(
Gitlab
::
Git
::
HooksService
::
PreReceiveError
)
...
...
@@ -1160,7 +1160,7 @@ describe Repository, models: true do
end
it
'sets autocrlf to :input'
do
GitOperationService
.
new
(
nil
,
repository
.
raw_repository
).
send
(
:update_autocrlf_option
)
Git
lab
::
Git
::
OperationService
.
new
(
nil
,
repository
.
raw_repository
).
send
(
:update_autocrlf_option
)
expect
(
repository
.
raw_repository
.
autocrlf
).
to
eq
(
:input
)
end
...
...
@@ -1175,7 +1175,7 @@ describe Repository, models: true do
expect
(
repository
.
raw_repository
).
not_to
receive
(
:autocrlf
=
)
.
with
(
:input
)
GitOperationService
.
new
(
nil
,
repository
.
raw_repository
).
send
(
:update_autocrlf_option
)
Git
lab
::
Git
::
OperationService
.
new
(
nil
,
repository
.
raw_repository
).
send
(
:update_autocrlf_option
)
end
end
end
...
...
@@ -1761,15 +1761,15 @@ describe Repository, models: true do
describe
'#update_ref'
do
it
'can create a ref'
do
GitOperationService
.
new
(
nil
,
repository
.
raw_repository
).
send
(
:update_ref
,
'refs/heads/foobar'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
Git
lab
::
Git
::
OperationService
.
new
(
nil
,
repository
.
raw_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
.
raw_repository
).
send
(
:update_ref
,
'refs/heads/master'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
end
.
to
raise_error
(
Repository
::
CommitError
)
Git
lab
::
Git
::
OperationService
.
new
(
nil
,
repository
.
raw_repository
).
send
(
:update_ref
,
'refs/heads/master'
,
'refs/heads/master'
,
Gitlab
::
Git
::
BLANK_SHA
)
end
.
to
raise_error
(
Gitlab
::
Git
::
CommitError
)
end
end
...
...
spec/requests/api/files_spec.rb
View file @
4efdb451
...
...
@@ -224,7 +224,7 @@ describe API::Files do
it
"returns a 400 if editor fails to create file"
do
allow_any_instance_of
(
Repository
).
to
receive
(
:create_file
)
.
and_raise
(
Repository
::
CommitError
,
'Cannot create file'
)
.
and_raise
(
Gitlab
::
Git
::
CommitError
,
'Cannot create file'
)
post
api
(
route
(
"any%2Etxt"
),
user
),
valid_params
...
...
@@ -339,7 +339,7 @@ describe API::Files do
end
it
"returns a 400 if fails to delete file"
do
allow_any_instance_of
(
Repository
).
to
receive
(
:delete_file
).
and_raise
(
Repository
::
CommitError
,
'Cannot delete file'
)
allow_any_instance_of
(
Repository
).
to
receive
(
:delete_file
).
and_raise
(
Gitlab
::
Git
::
CommitError
,
'Cannot delete file'
)
delete
api
(
route
(
file_path
),
user
),
valid_params
...
...
spec/requests/api/v3/files_spec.rb
View file @
4efdb451
...
...
@@ -127,7 +127,7 @@ describe API::V3::Files do
it
"returns a 400 if editor fails to create file"
do
allow_any_instance_of
(
Repository
).
to
receive
(
:create_file
)
.
and_raise
(
Repository
::
CommitError
,
'Cannot create file'
)
.
and_raise
(
Gitlab
::
Git
::
CommitError
,
'Cannot create file'
)
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
...
...
@@ -228,7 +228,7 @@ describe API::V3::Files do
end
it
"returns a 400 if fails to delete file"
do
allow_any_instance_of
(
Repository
).
to
receive
(
:delete_file
).
and_raise
(
Repository
::
CommitError
,
'Cannot delete file'
)
allow_any_instance_of
(
Repository
).
to
receive
(
:delete_file
).
and_raise
(
Gitlab
::
Git
::
CommitError
,
'Cannot delete file'
)
delete
v3_api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
...
...
spec/workers/git_garbage_collect_worker_spec.rb
View file @
4efdb451
...
...
@@ -143,7 +143,7 @@ describe GitGarbageCollectWorker do
tree:
old_commit
.
tree
,
parents:
[
old_commit
]
)
GitOperationService
.
new
(
nil
,
project
.
repository
.
raw_repository
).
send
(
Git
lab
::
Git
::
OperationService
.
new
(
nil
,
project
.
repository
.
raw_repository
).
send
(
:update_ref
,
"refs/heads/
#{
SecureRandom
.
hex
(
6
)
}
"
,
new_commit_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