Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
0
Merge Requests
0
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-shell
Commits
9e41159a
Commit
9e41159a
authored
Mar 16, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds timeout option to push branches and respective test suite
parent
6acaaa58
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
8 deletions
+94
-8
CHANGELOG
CHANGELOG
+3
-0
VERSION
VERSION
+1
-1
lib/gitlab_projects.rb
lib/gitlab_projects.rb
+10
-7
spec/gitlab_projects_spec.rb
spec/gitlab_projects_spec.rb
+80
-0
No files found.
CHANGELOG
View file @
9e41159a
v5.0.2
- Adds timeout option to push branches
v5.0.1
- Fetch repositories with `--quiet` option by default
...
...
VERSION
View file @
9e41159a
5.0.
0
5.0.
2
lib/gitlab_projects.rb
View file @
9e41159a
...
...
@@ -113,16 +113,21 @@ class GitlabProjects
def
push_branches
remote_name
=
ARGV
.
shift
# timeout for push
timeout
=
(
ARGV
.
shift
||
120
).
to_i
$logger
.
info
"Pushing branches from
#{
full_path
}
to remote
#{
remote_name
}
:
#{
ARGV
}
"
cmd
=
%W(git --git-dir=
#{
full_path
}
push --
#{
remote_name
}
)
.
concat
(
ARGV
)
pid
=
Process
.
spawn
(
*
cmd
)
begin
Process
.
wait
(
pid
)
Timeout
.
timeout
(
timeout
)
do
Process
.
wait
(
pid
)
end
$?
.
exitstatus
.
zero?
rescue
=>
exception
$logger
.
error
"Pushing branches to remote
#{
remote_name
}
failed due to:
#{
exception
.
message
}
"
$logger
.
error
"Pushing branches to remote
#{
remote_name
}
failed due to:
#{
exception
.
message
}
.
"
Process
.
kill
(
'KILL'
,
pid
)
Process
.
wait
...
...
@@ -204,10 +209,8 @@ class GitlabProjects
tags_option
=
ARGV
.
include?
(
'--no-tags'
)
?
'--no-tags'
:
'--tags'
$logger
.
info
"Fetching remote
#{
@name
}
for project
#{
@project_name
}
."
cmd
=
%W(git --git-dir=
#{
full_path
}
fetch
#{
@name
}
)
cmd
<<
'--prune'
cmd
=
%W(git --git-dir=
#{
full_path
}
fetch
#{
@name
}
--prune --quiet)
cmd
<<
'--force'
if
forced
cmd
<<
'--quiet'
cmd
<<
tags_option
pid
=
Process
.
spawn
(
*
cmd
)
...
...
@@ -217,8 +220,8 @@ class GitlabProjects
end
$?
.
exitstatus
.
zero?
rescue
Timeout
::
Error
$logger
.
error
"Fetching remote
#{
@name
}
for project
#{
@project_name
}
failed due to
timeout
."
rescue
=>
exception
$logger
.
error
"Fetching remote
#{
@name
}
for project
#{
@project_name
}
failed due to
:
#{
exception
.
message
}
."
Process
.
kill
(
'KILL'
,
pid
)
Process
.
wait
...
...
spec/gitlab_projects_spec.rb
View file @
9e41159a
...
...
@@ -287,6 +287,86 @@ describe GitlabProjects do
end
end
describe
:push_branches
do
let
(
:repos_path
)
{
'current/storage'
}
let
(
:project_name
)
{
'project/path.git'
}
let
(
:full_path
)
{
File
.
join
(
repos_path
,
project_name
)
}
let
(
:remote_name
)
{
'new/storage'
}
let
(
:pid
)
{
1234
}
let
(
:branch_name
)
{
'master'
}
let
(
:cmd
)
{
%W(git --git-dir=
#{
full_path
}
push --
#{
remote_name
}
#{
branch_name
}
)
}
let
(
:gl_projects
)
{
build_gitlab_projects
(
'push-branches'
,
repos_path
,
project_name
,
remote_name
,
'600'
,
'master'
)
}
it
'executes the command'
do
expect
(
Process
).
to
receive
(
:spawn
).
with
(
*
cmd
).
and_return
(
pid
)
expect
(
Process
).
to
receive
(
:wait
).
with
(
pid
)
expect
(
gl_projects
.
exec
).
to
be
true
end
it
'raises timeout'
do
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
600
).
and_raise
(
Timeout
::
Error
)
expect
(
Process
).
to
receive
(
:spawn
).
with
(
*
cmd
).
and_return
(
pid
)
expect
(
Process
).
to
receive
(
:wait
)
expect
(
Process
).
to
receive
(
:kill
).
with
(
'KILL'
,
pid
)
expect
(
gl_projects
.
exec
).
to
be
false
end
end
describe
:fetch_remote
do
let
(
:repos_path
)
{
'current/storage'
}
let
(
:project_name
)
{
'project.git'
}
let
(
:full_path
)
{
File
.
join
(
repos_path
,
project_name
)
}
let
(
:remote_name
)
{
'new/storage'
}
let
(
:pid
)
{
1234
}
let
(
:branch_name
)
{
'master'
}
describe
'with default args'
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'fetch-remote'
,
repos_path
,
project_name
,
remote_name
,
'600'
)
}
let
(
:cmd
)
{
%W(git --git-dir=
#{
full_path
}
fetch
#{
remote_name
}
--prune --quiet --tags)
}
it
'executes the command'
do
expect
(
Process
).
to
receive
(
:spawn
).
with
(
*
cmd
).
and_return
(
pid
)
expect
(
Process
).
to
receive
(
:wait
).
with
(
pid
)
expect
(
gl_projects
.
exec
).
to
be
true
end
it
'raises timeout'
do
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
600
).
and_raise
(
Timeout
::
Error
)
expect
(
Process
).
to
receive
(
:spawn
).
with
(
*
cmd
).
and_return
(
pid
)
expect
(
Process
).
to
receive
(
:wait
)
expect
(
Process
).
to
receive
(
:kill
).
with
(
'KILL'
,
pid
)
expect
(
gl_projects
.
exec
).
to
be
false
end
end
describe
'with --force'
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'fetch-remote'
,
repos_path
,
project_name
,
remote_name
,
'600'
,
'--force'
)
}
let
(
:cmd
)
{
%W(git --git-dir=
#{
full_path
}
fetch
#{
remote_name
}
--prune --quiet --force --tags)
}
it
'executes the command with forced option'
do
expect
(
Process
).
to
receive
(
:spawn
).
with
(
*
cmd
).
and_return
(
pid
)
expect
(
Process
).
to
receive
(
:wait
).
with
(
pid
)
expect
(
gl_projects
.
exec
).
to
be
true
end
end
describe
'with --no-tags'
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'fetch-remote'
,
repos_path
,
project_name
,
remote_name
,
'600'
,
'--no-tags'
)
}
let
(
:cmd
)
{
%W(git --git-dir=
#{
full_path
}
fetch
#{
remote_name
}
--prune --quiet --no-tags)
}
it
'executes the command'
do
expect
(
Process
).
to
receive
(
:spawn
).
with
(
*
cmd
).
and_return
(
pid
)
expect
(
Process
).
to
receive
(
:wait
).
with
(
pid
)
expect
(
gl_projects
.
exec
).
to
be
true
end
end
end
describe
:import_project
do
context
'success import'
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'import-project'
,
tmp_repos_path
,
repo_name
,
'https://github.com/randx/six.git'
)
}
...
...
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