Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add fork_project command
  • Loading branch information
amacarthur committed Apr 11, 2013
commit a471d5526249654f93dae8d88b92c2cddb287178
13 changes: 13 additions & 0 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 Down Expand Up @@ -84,4 +85,16 @@ 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 

cmd = "cd #{namespaced_path} && git clone --bare #{@full_path}"
system(cmd)
end
end
13 changes: 12 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,17 @@
end
end

describe :fork_project do
let(:gl_projects) { build_gitlab_projects('fork-project', repo_name, 'forked-to-namespace')}

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

Choose a reason for hiding this comment

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

this lines have no should so basically this test does not check anything at all

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