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
Kazuhiko Shiozaki
gitlab-shell
Commits
487b1bf2
Commit
487b1bf2
authored
Feb 13, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable git-annex on first command
parent
b8443a9c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
38 deletions
+72
-38
lib/gitlab_projects.rb
lib/gitlab_projects.rb
+0
-5
lib/gitlab_shell.rb
lib/gitlab_shell.rb
+14
-9
spec/gitlab_shell_spec.rb
spec/gitlab_shell_spec.rb
+58
-24
No files found.
lib/gitlab_projects.rb
View file @
487b1bf2
...
...
@@ -238,9 +238,4 @@ class GitlabProjects
$logger
.
info
"Update head in project
#{
project_name
}
to <
#{
new_head
}
>."
true
end
def
git_init_annex
cmd
=
%W(git --git-dir=
#{
full_path
}
annex init "GitLab")
system
(
*
cmd
)
end
end
lib/gitlab_shell.rb
View file @
487b1bf2
...
...
@@ -48,20 +48,15 @@ class GitlabShell
def
parse_cmd
args
=
Shellwords
.
shellwords
(
@origin_cmd
)
if
args
.
first
==
'git-annex-shell'
# Dont know yet how much arguments allow
# puts args.count
# puts args.inspect
else
raise
DisallowedCommandError
unless
args
.
count
==
2
end
@git_cmd
=
args
.
first
if
@git_cmd
==
'git-annex-shell'
@repo_name
=
escape_path
(
args
[
2
].
gsub
(
"
\/
~
\/
"
,
''
))
# Make sure repository has git-annex enabled
enable_git_annex
(
@repo_name
)
else
raise
DisallowedCommandError
unless
args
.
count
==
2
@repo_name
=
escape_path
(
args
.
last
)
end
end
...
...
@@ -131,4 +126,14 @@ class GitlabShell
abort
"Wrong repository path"
end
end
def
enable_git_annex
(
path
)
full_repo_path
=
File
.
join
(
repos_path
,
path
)
unless
File
.
exists?
(
File
.
join
(
full_repo_path
,
'.git'
,
'annex'
))
cmd
=
%W(git --git-dir=
#{
full_repo_path
}
annex init "GitLab")
system
(
*
cmd
)
$logger
.
info
"Enable git-annex for repository:
#{
path
}
."
end
end
end
spec/gitlab_shell_spec.rb
View file @
487b1bf2
...
...
@@ -3,6 +3,14 @@ require_relative '../lib/gitlab_shell'
require_relative
'../lib/gitlab_access_status'
describe
GitlabShell
do
before
do
FileUtils
.
mkdir_p
(
tmp_repos_path
)
end
after
do
FileUtils
.
rm_rf
(
tmp_repos_path
)
end
subject
do
ARGV
[
0
]
=
key_id
GitlabShell
.
new
.
tap
do
|
shell
|
...
...
@@ -10,51 +18,77 @@ describe GitlabShell do
shell
.
stub
(
api:
api
)
end
end
let
(
:api
)
do
double
(
GitlabNet
).
tap
do
|
api
|
api
.
stub
(
discover:
{
'name'
=>
'John Doe'
})
api
.
stub
(
check_access:
GitAccessStatus
.
new
(
true
))
end
end
let
(
:key_id
)
{
"key-
#{
rand
(
100
)
+
100
}
"
}
let
(
:repository_path
)
{
"/home/git
#{
rand
(
100
)
}
/repos"
}
let
(
:tmp_repos_path
)
{
File
.
join
(
ROOT_PATH
,
'tmp'
,
'repositories'
)
}
before
do
GitlabConfig
.
any_instance
.
stub
(
repos_path:
repository
_path
,
audit_usernames:
false
)
GitlabConfig
.
any_instance
.
stub
(
repos_path:
tmp_repos
_path
,
audit_usernames:
false
)
end
describe
:initialize
do
before
{
ssh_cmd
'git-receive-pack'
}
its
(
:key_id
)
{
should
==
key_id
}
its
(
:repos_path
)
{
should
==
repository
_path
}
its
(
:repos_path
)
{
should
==
tmp_repos
_path
}
end
describe
:parse_cmd
do
context
'w/o namespace'
do
before
do
ssh_cmd
'git-upload-pack gitlab-ci.git'
subject
.
send
:parse_cmd
describe
'git'
do
context
'w/o namespace'
do
before
do
ssh_cmd
'git-upload-pack gitlab-ci.git'
subject
.
send
:parse_cmd
end
its
(
:repo_name
)
{
should
==
'gitlab-ci.git'
}
its
(
:git_cmd
)
{
should
==
'git-upload-pack'
}
end
its
(
:repo_name
)
{
should
==
'gitlab-ci.git'
}
its
(
:git_cmd
)
{
should
==
'git-upload-pack'
}
context
'namespace'
do
before
do
ssh_cmd
'git-upload-pack dmitriy.zaporozhets/gitlab-ci.git'
subject
.
send
:parse_cmd
end
its
(
:repo_name
)
{
should
==
'dmitriy.zaporozhets/gitlab-ci.git'
}
its
(
:git_cmd
)
{
should
==
'git-upload-pack'
}
end
context
'with an invalid number of arguments'
do
before
{
ssh_cmd
'foobar'
}
it
"should raise an DisallowedCommandError"
do
expect
{
subject
.
send
:parse_cmd
}.
to
raise_error
(
GitlabShell
::
DisallowedCommandError
)
end
end
end
context
'namespace'
do
describe
'git-annex'
do
let
(
:repo_path
)
{
File
.
join
(
tmp_repos_path
,
'dzaporozhets/gitlab.git'
)
}
before
do
ssh_cmd
'git-upload-pack dmitriy.zaporozhets/gitlab-ci.git'
# Create existing project
FileUtils
.
mkdir_p
(
repo_path
)
cmd
=
%W(git --git-dir=
#{
repo_path
}
init --bare)
system
(
*
cmd
)
ssh_cmd
'git-annex-shell inannex /~/dzaporozhets/gitlab.git SHA256E'
subject
.
send
:parse_cmd
end
its
(
:repo_name
)
{
should
==
'dmitriy.zaporozhets/gitlab-ci.git'
}
its
(
:git_cmd
)
{
should
==
'git-upload-pack'
}
end
context
'with an invalid number of arguments'
do
before
{
ssh_cmd
'foobar'
}
its
(
:repo_name
)
{
should
==
'dzaporozhets/gitlab.git'
}
its
(
:git_cmd
)
{
should
==
'git-annex-shell'
}
it
"should raise an DisallowedCommandError"
do
expect
{
subject
.
send
:parse_cmd
}.
to
raise_error
(
GitlabShell
::
DisallowedCommandError
)
it
'should init git-annex'
do
File
.
exists?
(
File
.
join
(
tmp_repos_path
,
'dzaporozhets/gitlab.git/annex'
)).
should
be_true
end
end
end
...
...
@@ -69,7 +103,7 @@ describe GitlabShell do
end
it
"should execute the command"
do
subject
.
should_receive
(
:exec_cmd
).
with
(
"git-upload-pack"
,
File
.
join
(
repository
_path
,
'gitlab-ci.git'
))
subject
.
should_receive
(
:exec_cmd
).
with
(
"git-upload-pack"
,
File
.
join
(
tmp_repos
_path
,
'gitlab-ci.git'
))
end
it
"should set the GL_ID environment variable"
do
...
...
@@ -78,7 +112,7 @@ describe GitlabShell do
it
"should log the command execution"
do
message
=
"gitlab-shell: executing git command "
message
<<
"<git-upload-pack
#{
File
.
join
(
repository
_path
,
'gitlab-ci.git'
)
}
> "
message
<<
"<git-upload-pack
#{
File
.
join
(
tmp_repos
_path
,
'gitlab-ci.git'
)
}
> "
message
<<
"for user with key
#{
key_id
}
."
$logger
.
should_receive
(
:info
).
with
(
message
)
end
...
...
@@ -98,12 +132,12 @@ describe GitlabShell do
end
it
"should execute the command"
do
subject
.
should_receive
(
:exec_cmd
).
with
(
"git-receive-pack"
,
File
.
join
(
repository
_path
,
'gitlab-ci.git'
))
subject
.
should_receive
(
:exec_cmd
).
with
(
"git-receive-pack"
,
File
.
join
(
tmp_repos
_path
,
'gitlab-ci.git'
))
end
it
"should log the command execution"
do
message
=
"gitlab-shell: executing git command "
message
<<
"<git-receive-pack
#{
File
.
join
(
repository
_path
,
'gitlab-ci.git'
)
}
> "
message
<<
"<git-receive-pack
#{
File
.
join
(
tmp_repos
_path
,
'gitlab-ci.git'
)
}
> "
message
<<
"for user with key
#{
key_id
}
."
$logger
.
should_receive
(
:info
).
with
(
message
)
end
...
...
@@ -137,7 +171,7 @@ describe GitlabShell do
end
context
"failed connection"
do
before
{
before
{
ssh_cmd
'git-upload-pack gitlab-ci.git'
api
.
stub
(
:check_access
).
and_raise
(
GitlabNet
::
ApiUnreachableError
)
}
...
...
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