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
43308bd8
Commit
43308bd8
authored
Dec 18, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move push_remote_branches from Gitlab::Shell to Gitlab::Git::Repository
parent
fb583c4b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
52 deletions
+56
-52
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+18
-1
lib/gitlab/shell.rb
lib/gitlab/shell.rb
+0
-21
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+38
-2
spec/lib/gitlab/shell_spec.rb
spec/lib/gitlab/shell_spec.rb
+0
-28
No files found.
lib/gitlab/git/repository.rb
View file @
43308bd8
...
...
@@ -21,6 +21,7 @@ module Gitlab
REBASE_WORKTREE_PREFIX
=
'rebase'
.
freeze
SQUASH_WORKTREE_PREFIX
=
'squash'
.
freeze
GITALY_INTERNAL_URL
=
'ssh://gitaly/internal.git'
.
freeze
GITLAB_PROJECTS_TIMEOUT
=
Gitlab
.
config
.
gitlab_shell
.
git_timeout
NoRepository
=
Class
.
new
(
StandardError
)
InvalidBlobName
=
Class
.
new
(
StandardError
)
...
...
@@ -83,7 +84,7 @@ module Gitlab
# Rugged repo object
attr_reader
:rugged
attr_reader
:storage
,
:gl_repository
,
:relative_path
attr_reader
:
gitlab_projects
,
:
storage
,
:gl_repository
,
:relative_path
# This initializer method is only used on the client side (gitlab-ce).
# Gitaly-ruby uses a different initializer.
...
...
@@ -93,6 +94,12 @@ module Gitlab
@gl_repository
=
gl_repository
storage_path
=
Gitlab
.
config
.
repositories
.
storages
[
@storage
][
'path'
]
@gitlab_projects
=
Gitlab
::
Git
::
GitlabProjects
.
new
(
storage_path
,
relative_path
,
global_hooks_path:
Gitlab
.
config
.
gitlab_shell
.
hooks_path
,
logger:
Rails
.
logger
)
@path
=
File
.
join
(
storage_path
,
@relative_path
)
@name
=
@relative_path
.
split
(
"/"
).
last
@attributes
=
Gitlab
::
Git
::
Attributes
.
new
(
path
)
...
...
@@ -1266,6 +1273,12 @@ module Gitlab
fresh_worktree?
(
worktree_path
(
SQUASH_WORKTREE_PREFIX
,
squash_id
))
end
def
push_remote_branches
(
remote_name
,
branch_names
,
forced:
true
)
success
=
@gitlab_projects
.
push_branches
(
remote_name
,
GITLAB_PROJECTS_TIMEOUT
,
forced
,
branch_names
)
success
||
gitlab_projects_error
end
def
gitaly_repository
Gitlab
::
GitalyClient
::
Util
.
repository
(
@storage
,
@relative_path
,
@gl_repository
)
end
...
...
@@ -1943,6 +1956,10 @@ module Gitlab
def
fetch_remote
(
remote_name
=
'origin'
,
env:
nil
)
run_git
([
'fetch'
,
remote_name
],
env:
env
).
last
.
zero?
end
def
gitlab_projects_error
raise
CommandError
,
@gitlab_projects
.
output
end
end
end
end
lib/gitlab/shell.rb
View file @
43308bd8
...
...
@@ -306,27 +306,6 @@ module Gitlab
end
end
# Push branch to remote repository
#
# storage - project's storage path
# project_name - project's disk path
# remote_name - remote name
# branch_names - remote branch names to push
# forced - should we use --force flag
#
# Ex.
# push_remote_branches('/path/to/storage', 'gitlab-org/gitlab-test' 'upstream', ['feature'])
#
def
push_remote_branches
(
storage
,
project_name
,
remote_name
,
branch_names
,
forced:
true
)
cmd
=
gitlab_projects
(
storage
,
"
#{
project_name
}
.git"
)
success
=
cmd
.
push_branches
(
remote_name
,
git_timeout
,
forced
,
branch_names
)
raise
Error
,
cmd
.
output
unless
success
success
end
# Delete branch from remote repository
#
# storage - project's storage path
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
43308bd8
...
...
@@ -18,9 +18,10 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
,
''
)
}
let
(
:storage_path
)
{
TestEnv
.
repos_path
}
describe
'.create_hooks'
do
let
(
:repo_path
)
{
File
.
join
(
TestEnv
.
repos
_path
,
'hook-test.git'
)
}
let
(
:repo_path
)
{
File
.
join
(
storage
_path
,
'hook-test.git'
)
}
let
(
:hooks_dir
)
{
File
.
join
(
repo_path
,
'hooks'
)
}
let
(
:target_hooks_dir
)
{
Gitlab
.
config
.
gitlab_shell
.
hooks_path
}
let
(
:existing_target
)
{
File
.
join
(
repo_path
,
'foobar'
)
}
...
...
@@ -645,7 +646,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
after
do
Gitlab
::
Shell
.
new
.
remove_repository
(
TestEnv
.
repos
_path
,
'my_project'
)
Gitlab
::
Shell
.
new
.
remove_repository
(
storage
_path
,
'my_project'
)
end
it
'fetches a repository as a mirror remote'
do
...
...
@@ -1884,6 +1885,41 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#gitlab_projects'
do
subject
{
repository
.
gitlab_projects
}
it
{
expect
(
subject
.
shard_path
).
to
eq
(
storage_path
)
}
it
{
expect
(
subject
.
repository_relative_path
).
to
eq
(
repository
.
relative_path
)
}
end
context
'gitlab_projects commands'
do
let
(
:gitlab_projects
)
{
repository
.
gitlab_projects
}
let
(
:timeout
)
{
Gitlab
.
config
.
gitlab_shell
.
git_timeout
}
describe
'#push_remote_branches'
do
subject
do
repository
.
push_remote_branches
(
'downstream-remote'
,
[
'master'
])
end
it
'executes the command'
do
expect
(
gitlab_projects
).
to
receive
(
:push_branches
)
.
with
(
'downstream-remote'
,
timeout
,
true
,
[
'master'
])
.
and_return
(
true
)
is_expected
.
to
be_truthy
end
it
'raises an error if the command fails'
do
allow
(
gitlab_projects
).
to
receive
(
:output
)
{
'error'
}
expect
(
gitlab_projects
).
to
receive
(
:push_branches
)
.
with
(
'downstream-remote'
,
timeout
,
true
,
[
'master'
])
.
and_return
(
false
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Git
::
CommandError
,
'error'
)
end
end
end
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_branch_name
)
source_branch
=
repository
.
branches
.
find
{
|
branch
|
branch
.
name
==
source_branch_name
}
rugged
=
repository
.
rugged
...
...
spec/lib/gitlab/shell_spec.rb
View file @
43308bd8
...
...
@@ -348,34 +348,6 @@ describe Gitlab::Shell do
end
end
describe
'#push_remote_branches'
do
subject
(
:result
)
do
gitlab_shell
.
push_remote_branches
(
project
.
repository_storage_path
,
project
.
disk_path
,
'downstream-remote'
,
[
'master'
]
)
end
it
'executes the command'
do
expect
(
gitlab_projects
).
to
receive
(
:push_branches
)
.
with
(
'downstream-remote'
,
timeout
,
true
,
[
'master'
])
.
and_return
(
true
)
is_expected
.
to
be_truthy
end
it
'fails to execute the command'
do
allow
(
gitlab_projects
).
to
receive
(
:output
)
{
'error'
}
expect
(
gitlab_projects
).
to
receive
(
:push_branches
)
.
with
(
'downstream-remote'
,
timeout
,
true
,
[
'master'
])
.
and_return
(
false
)
expect
{
result
}.
to
raise_error
(
Gitlab
::
Shell
::
Error
,
'error'
)
end
end
describe
'#delete_remote_branches'
do
subject
(
:result
)
do
gitlab_shell
.
delete_remote_branches
(
...
...
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