Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9b930932
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9b930932
编写于
8月 22, 2017
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Decouple GitOperationService from User
上级
0f74ba96
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
60 addition
and
26 deletion
+60
-26
app/models/repository.rb
app/models/repository.rb
+18
-9
app/services/git_hooks_service.rb
app/services/git_hooks_service.rb
+3
-3
app/services/git_operation_service.rb
app/services/git_operation_service.rb
+7
-4
lib/gitlab/git/committer.rb
lib/gitlab/git/committer.rb
+21
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+11
-10
未找到文件。
app/models/repository.rb
浏览文件 @
9b930932
...
...
@@ -164,7 +164,8 @@ class Repository
return
false
unless
newrev
GitOperationService
.
new
(
user
,
self
).
add_branch
(
branch_name
,
newrev
)
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
add_branch
(
branch_name
,
newrev
)
after_create_branch
find_branch
(
branch_name
)
...
...
@@ -176,7 +177,8 @@ class Repository
return
false
unless
newrev
GitOperationService
.
new
(
user
,
self
).
add_tag
(
tag_name
,
newrev
,
options
)
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
add_tag
(
tag_name
,
newrev
,
options
)
find_tag
(
tag_name
)
end
...
...
@@ -185,7 +187,8 @@ class Repository
before_remove_branch
branch
=
find_branch
(
branch_name
)
GitOperationService
.
new
(
user
,
self
).
rm_branch
(
branch
)
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
rm_branch
(
branch
)
after_remove_branch
true
...
...
@@ -195,7 +198,8 @@ class Repository
before_remove_tag
tag
=
find_tag
(
tag_name
)
GitOperationService
.
new
(
user
,
self
).
rm_tag
(
tag
)
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
rm_tag
(
tag
)
after_remove_tag
true
...
...
@@ -763,7 +767,8 @@ class Repository
author_email:
nil
,
author_name:
nil
,
start_branch_name:
nil
,
start_project:
project
)
GitOperationService
.
new
(
user
,
self
).
with_branch
(
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
with_branch
(
branch_name
,
start_branch_name:
start_branch_name
,
start_project:
start_project
)
do
|
start_commit
|
...
...
@@ -819,7 +824,8 @@ class Repository
end
def
merge
(
user
,
source
,
merge_request
,
options
=
{})
GitOperationService
.
new
(
user
,
self
).
with_branch
(
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
with_branch
(
merge_request
.
target_branch
)
do
|
start_commit
|
our_commit
=
start_commit
.
sha
their_commit
=
source
...
...
@@ -846,7 +852,8 @@ class Repository
def
revert
(
user
,
commit
,
branch_name
,
start_branch_name:
nil
,
start_project:
project
)
GitOperationService
.
new
(
user
,
self
).
with_branch
(
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
with_branch
(
branch_name
,
start_branch_name:
start_branch_name
,
start_project:
start_project
)
do
|
start_commit
|
...
...
@@ -869,7 +876,8 @@ class Repository
def
cherry_pick
(
user
,
commit
,
branch_name
,
start_branch_name:
nil
,
start_project:
project
)
GitOperationService
.
new
(
user
,
self
).
with_branch
(
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
with_branch
(
branch_name
,
start_branch_name:
start_branch_name
,
start_project:
start_project
)
do
|
start_commit
|
...
...
@@ -894,7 +902,8 @@ class Repository
end
def
resolve_conflicts
(
user
,
branch_name
,
params
)
GitOperationService
.
new
(
user
,
self
).
with_branch
(
branch_name
)
do
committer
=
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
GitOperationService
.
new
(
committer
,
self
).
with_branch
(
branch_name
)
do
committer
=
user_to_committer
(
user
)
create_commit
(
params
.
merge
(
author:
committer
,
committer:
committer
))
...
...
app/services/git_hooks_service.rb
浏览文件 @
9b930932
...
...
@@ -3,9 +3,9 @@ class GitHooksService
attr_accessor
:oldrev
,
:newrev
,
:ref
def
execute
(
us
er
,
project
,
oldrev
,
newrev
,
ref
)
def
execute
(
committ
er
,
project
,
oldrev
,
newrev
,
ref
)
@project
=
project
@
user
=
Gitlab
::
GlId
.
gl_id
(
user
)
@
gl_id
=
committer
.
gl_id
@oldrev
=
oldrev
@newrev
=
newrev
@ref
=
ref
...
...
@@ -27,6 +27,6 @@ class GitHooksService
def
run_hook
(
name
)
hook
=
Gitlab
::
Git
::
Hook
.
new
(
name
,
@project
)
hook
.
trigger
(
@
user
,
oldrev
,
newrev
,
ref
)
hook
.
trigger
(
@
gl_id
,
oldrev
,
newrev
,
ref
)
end
end
app/services/git_operation_service.rb
浏览文件 @
9b930932
class
GitOperationService
attr_reader
:
us
er
,
:repository
attr_reader
:
committ
er
,
:repository
def
initialize
(
new_user
,
new_repository
)
@user
=
new_user
def
initialize
(
committer
,
new_repository
)
if
committer
&&
!
committer
.
is_a?
(
Gitlab
::
Git
::
Committer
)
raise
"expected Gitlab::Git::Committer, got
#{
committer
.
inspect
}
"
end
@committer
=
committer
@repository
=
new_repository
end
...
...
@@ -119,7 +122,7 @@ class GitOperationService
def
with_hooks
(
ref
,
newrev
,
oldrev
)
GitHooksService
.
new
.
execute
(
us
er
,
committ
er
,
repository
.
project
,
oldrev
,
newrev
,
...
...
lib/gitlab/git/committer.rb
0 → 100644
浏览文件 @
9b930932
module
Gitlab
module
Git
class
Committer
attr_reader
:name
,
:email
,
:gl_id
def
self
.
from_user
(
user
)
new
(
user
.
name
,
user
.
email
,
Gitlab
::
GlId
.
gl_id
(
user
))
end
def
initialize
(
name
,
email
,
gl_id
)
@name
=
name
@email
=
email
@gl_id
=
gl_id
end
def
==
(
other
)
[
name
,
email
,
gl_id
]
==
[
other
.
name
,
other
.
email
,
other
.
gl_id
]
end
end
end
end
spec/models/repository_spec.rb
浏览文件 @
9b930932
...
...
@@ -8,6 +8,7 @@ describe Repository, models: true do
let
(
:repository
)
{
project
.
repository
}
let
(
:broken_repository
)
{
create
(
:project
,
:broken_storage
).
repository
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:committer
)
{
Gitlab
::
Git
::
Committer
.
from_user
(
user
)
}
let
(
:commit_options
)
do
author
=
repository
.
user_to_committer
(
user
)
...
...
@@ -885,7 +886,7 @@ describe Repository, models: true do
context
'when pre hooks were successful'
do
it
'runs without errors'
do
expect_any_instance_of
(
GitHooksService
).
to
receive
(
:execute
)
.
with
(
us
er
,
project
,
old_rev
,
blank_sha
,
'refs/heads/feature'
)
.
with
(
committ
er
,
project
,
old_rev
,
blank_sha
,
'refs/heads/feature'
)
expect
{
repository
.
rm_branch
(
user
,
'feature'
)
}.
not_to
raise_error
end
...
...
@@ -928,20 +929,20 @@ describe Repository, models: true do
service
=
GitHooksService
.
new
expect
(
GitHooksService
).
to
receive
(
:new
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
.
with
(
us
er
,
project
,
old_rev
,
new_rev
,
'refs/heads/feature'
)
.
with
(
committ
er
,
project
,
old_rev
,
new_rev
,
'refs/heads/feature'
)
.
and_yield
(
service
).
and_return
(
true
)
end
it
'runs without errors'
do
expect
do
GitOperationService
.
new
(
us
er
,
repository
).
with_branch
(
'feature'
)
do
GitOperationService
.
new
(
committ
er
,
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
(
us
er
,
repository
)
service
=
GitOperationService
.
new
(
committ
er
,
repository
)
expect
(
service
).
to
receive
(
:update_autocrlf_option
)
...
...
@@ -952,7 +953,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
(
us
er
,
repository
).
with_branch
(
'feature'
)
do
GitOperationService
.
new
(
committ
er
,
repository
).
with_branch
(
'feature'
)
do
new_rev
end
...
...
@@ -974,7 +975,7 @@ describe Repository, models: true do
end
expect
do
GitOperationService
.
new
(
us
er
,
target_project
.
repository
)
GitOperationService
.
new
(
committ
er
,
target_project
.
repository
)
.
with_branch
(
'feature'
,
start_project:
project
,
&
:itself
)
...
...
@@ -996,7 +997,7 @@ describe Repository, models: true do
repository
.
add_branch
(
user
,
branch
,
old_rev
)
expect
do
GitOperationService
.
new
(
us
er
,
repository
).
with_branch
(
branch
)
do
GitOperationService
.
new
(
committ
er
,
repository
).
with_branch
(
branch
)
do
new_rev
end
end
.
not_to
raise_error
...
...
@@ -1014,7 +1015,7 @@ 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
(
us
er
,
repository
).
with_branch
(
branch
)
do
GitOperationService
.
new
(
committ
er
,
repository
).
with_branch
(
branch
)
do
new_rev
end
end
.
to
raise_error
(
Repository
::
CommitError
)
...
...
@@ -1026,7 +1027,7 @@ describe Repository, models: true do
allow_any_instance_of
(
Gitlab
::
Git
::
Hook
).
to
receive
(
:trigger
).
and_return
([
false
,
''
])
expect
do
GitOperationService
.
new
(
us
er
,
repository
).
with_branch
(
'feature'
)
do
GitOperationService
.
new
(
committ
er
,
repository
).
with_branch
(
'feature'
)
do
new_rev
end
end
.
to
raise_error
(
GitHooksService
::
PreReceiveError
)
...
...
@@ -1044,7 +1045,7 @@ describe Repository, models: true do
expect
(
repository
).
not_to
receive
(
:expire_emptiness_caches
)
expect
(
repository
).
to
receive
(
:expire_branches_cache
)
GitOperationService
.
new
(
us
er
,
repository
)
GitOperationService
.
new
(
committ
er
,
repository
)
.
with_branch
(
'new-feature'
)
do
new_rev
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录