Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Import repo

./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:

Expand Down
2 changes: 2 additions & 0 deletions bin/gitlab-projects
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require_relative '../lib/gitlab_init'
#
# /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
#
require File.join(ROOT_PATH, 'lib', 'gitlab_projects')
Expand Down
30 changes: 26 additions & 4 deletions lib/gitlab_projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def exec
when 'rm-project'; rm_project
when 'mv-project'; mv_project
when 'import-project'; import_project
when 'fork-project'; fork_project
else
puts 'not allowed'
false
Expand All @@ -44,10 +45,7 @@ def add_project
end

def create_hooks_cmd
pr_hook_path = File.join(ROOT_PATH, 'hooks', 'post-receive')
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"
create_hooks_to(full_path)
end

def rm_project
Expand Down Expand Up @@ -84,4 +82,28 @@ def mv_project

FileUtils.mv(full_path, new_full_path)
end

def fork_project
new_namespace = ARGV.shift

return false unless new_namespace

namespaced_path = File.join(repos_path, new_namespace)
return false unless File.exists?(namespaced_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check for existence of repo with same name in new_namespace.
Maybe something like
return false if File.exists?(File.join(namespaced_path, repository))

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. I will update.

I was wondering if you had any plans to add logging to gitlab-shell? There currently doesn't seem to be a good way to diagnose failures when they happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes minimal logging will be great. Like:

[17/Apr/2013 09:13:57] create-projects test/repo.git [17/Apr/2013 09:13:58] fork-projects test/repo.git randx 
full_destination_path = File.join(namespaced_path, project_name)

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
20 changes: 19 additions & 1 deletion spec/gitlab_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

it { @gl_projects.project_name.should == repo_name }
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

describe :add_project do
Expand Down Expand Up @@ -77,6 +77,24 @@
end
end

describe :fork_project do
let(:gl_project_import) { build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git') }
let(:gl_projects) { build_gitlab_projects('fork-project', repo_name, 'forked-to-namespace')}

before do
FileUtils.mkdir_p(tmp_repo_path)
FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace'))
gl_project_import.exec
end

it "should fork the repo" do
gl_projects.exec
File.exists?(File.join(tmp_repos_path, 'forked-to-namespace', repo_name)).should be_true
File.exists?(File.join(tmp_repos_path, 'forked-to-namespace', repo_name, '/hooks/update')).should be_true
File.exists?(File.join(tmp_repos_path, 'forked-to-namespace', repo_name, '/hooks/post-receive')).should be_true
end
end

describe :exec do
it 'should puts message if unknown command arg' do
gitlab_projects = build_gitlab_projects('edit-project', repo_name)
Expand Down