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
335f9e81
Commit
335f9e81
authored
Apr 16, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #45 from amacarthur/fork-feature
add fork_project command
parents
8e75018c
d8e061d7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
6 deletions
+68
-6
README.md
README.md
+4
-0
bin/gitlab-projects
bin/gitlab-projects
+2
-0
lib/gitlab_projects.rb
lib/gitlab_projects.rb
+31
-4
spec/gitlab_projects_spec.rb
spec/gitlab_projects_spec.rb
+31
-2
No files found.
README.md
View file @
335f9e81
...
@@ -33,6 +33,10 @@ Import repo
...
@@ -33,6 +33,10 @@ Import repo
./bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
./bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
Fork repo
./bin/gitlab-projects fork-project gitlab/gitlab-ci.git randx
### Keys:
### Keys:
...
...
bin/gitlab-projects
View file @
335f9e81
...
@@ -13,6 +13,8 @@ require_relative '../lib/gitlab_init'
...
@@ -13,6 +13,8 @@ require_relative '../lib/gitlab_init'
#
#
# /bin/gitlab-projects mv-project gitlab/gitlab-ci.git randx/fork.git
# /bin/gitlab-projects mv-project gitlab/gitlab-ci.git randx/fork.git
#
#
# /bin/gitlab-projects fork-project gitlab/gitlab-ci.git randx
#
# /bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
# /bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
#
#
require
File
.
join
(
ROOT_PATH
,
'lib'
,
'gitlab_projects'
)
require
File
.
join
(
ROOT_PATH
,
'lib'
,
'gitlab_projects'
)
...
...
lib/gitlab_projects.rb
View file @
335f9e81
...
@@ -29,6 +29,7 @@ class GitlabProjects
...
@@ -29,6 +29,7 @@ class GitlabProjects
when
'rm-project'
;
rm_project
when
'rm-project'
;
rm_project
when
'mv-project'
;
mv_project
when
'mv-project'
;
mv_project
when
'import-project'
;
import_project
when
'import-project'
;
import_project
when
'fork-project'
;
fork_project
else
else
puts
'not allowed'
puts
'not allowed'
false
false
...
@@ -44,10 +45,7 @@ class GitlabProjects
...
@@ -44,10 +45,7 @@ class GitlabProjects
end
end
def
create_hooks_cmd
def
create_hooks_cmd
pr_hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'post-receive'
)
create_hooks_to
(
full_path
)
up_hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'update'
)
"ln -s
#{
pr_hook_path
}
#{
full_path
}
/hooks/post-receive && ln -s
#{
up_hook_path
}
#{
full_path
}
/hooks/update"
end
end
def
rm_project
def
rm_project
...
@@ -84,4 +82,33 @@ class GitlabProjects
...
@@ -84,4 +82,33 @@ class GitlabProjects
FileUtils
.
mv
(
full_path
,
new_full_path
)
FileUtils
.
mv
(
full_path
,
new_full_path
)
end
end
def
fork_project
new_namespace
=
ARGV
.
shift
# destination namespace must be provided
return
false
unless
new_namespace
#destination namespace must exist
namespaced_path
=
File
.
join
(
repos_path
,
new_namespace
)
return
false
unless
File
.
exists?
(
namespaced_path
)
#a project of the same name cannot already be within the destination namespace
full_destination_path
=
File
.
join
(
namespaced_path
,
project_name
.
split
(
'/'
)[
-
1
])
return
false
if
File
.
exists?
(
full_destination_path
)
cmd
=
"cd
#{
namespaced_path
}
&& git clone --bare
#{
full_path
}
&&
#{
create_hooks_to
(
full_destination_path
)
}
"
system
(
cmd
)
end
private
def
create_hooks_to
(
dest_path
)
pr_hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'post-receive'
)
up_hook_path
=
File
.
join
(
ROOT_PATH
,
'hooks'
,
'update'
)
"ln -s
#{
pr_hook_path
}
#{
dest_path
}
/hooks/post-receive && ln -s
#{
up_hook_path
}
#{
dest_path
}
/hooks/update"
end
end
end
spec/gitlab_projects_spec.rb
View file @
335f9e81
...
@@ -18,7 +18,7 @@ describe GitlabProjects do
...
@@ -18,7 +18,7 @@ describe GitlabProjects do
it
{
@gl_projects
.
project_name
.
should
==
repo_name
}
it
{
@gl_projects
.
project_name
.
should
==
repo_name
}
it
{
@gl_projects
.
instance_variable_get
(
:@command
).
should
==
'add-project'
}
it
{
@gl_projects
.
instance_variable_get
(
:@command
).
should
==
'add-project'
}
it
{
@gl_projects
.
instance_variable_get
(
:@full_path
).
should
==
'/home/git/repositories/gitlab-ci.git'
}
it
{
@gl_projects
.
instance_variable_get
(
:@full_path
).
should
==
"
#{
GitlabConfig
.
new
.
repos_path
}
/gitlab-ci.git"
}
end
end
describe
:add_project
do
describe
:add_project
do
...
@@ -77,6 +77,35 @@ describe GitlabProjects do
...
@@ -77,6 +77,35 @@ describe GitlabProjects do
end
end
end
end
describe
:fork_project
do
let
(
:source_repo_name
)
{
File
.
join
(
'source-namespace'
,
repo_name
)
}
let
(
:dest_repo
)
{
File
.
join
(
tmp_repos_path
,
'forked-to-namespace'
,
repo_name
)
}
let
(
:gl_projects_fork
)
{
build_gitlab_projects
(
'fork-project'
,
source_repo_name
,
'forked-to-namespace'
)
}
let
(
:gl_projects_import
)
{
build_gitlab_projects
(
'import-project'
,
source_repo_name
,
'https://github.com/randx/six.git'
)
}
before
do
gl_projects_import
.
exec
end
it
"should not fork into a namespace that doesn't exist"
do
gl_projects_fork
.
exec
.
should
be_false
end
it
"should fork the repo"
do
# create destination namespace
FileUtils
.
mkdir_p
(
File
.
join
(
tmp_repos_path
,
'forked-to-namespace'
))
gl_projects_fork
.
exec
.
should
be_true
File
.
exists?
(
dest_repo
).
should
be_true
File
.
exists?
(
File
.
join
(
dest_repo
,
'/hooks/update'
)).
should
be_true
File
.
exists?
(
File
.
join
(
dest_repo
,
'/hooks/post-receive'
)).
should
be_true
end
it
"should not fork if a project of the same name already exists"
do
#trying to fork again should fail as the repo already exists
gl_projects_fork
.
exec
.
should
be_false
end
end
describe
:exec
do
describe
:exec
do
it
'should puts message if unknown command arg'
do
it
'should puts message if unknown command arg'
do
gitlab_projects
=
build_gitlab_projects
(
'edit-project'
,
repo_name
)
gitlab_projects
=
build_gitlab_projects
(
'edit-project'
,
repo_name
)
...
@@ -89,7 +118,7 @@ describe GitlabProjects do
...
@@ -89,7 +118,7 @@ describe GitlabProjects do
argv
(
*
args
)
argv
(
*
args
)
gl_projects
=
GitlabProjects
.
new
gl_projects
=
GitlabProjects
.
new
gl_projects
.
stub
(
repos_path:
tmp_repos_path
)
gl_projects
.
stub
(
repos_path:
tmp_repos_path
)
gl_projects
.
stub
(
full_path:
tmp_repo_path
)
gl_projects
.
stub
(
full_path:
File
.
join
(
tmp_repos_path
,
gl_projects
.
project_name
)
)
gl_projects
gl_projects
end
end
...
...
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