Commit 7ba6725f authored by Jacob Vosmaer's avatar Jacob Vosmaer

Bypass the shell in GitlabProjects

parent e76ad1dc
...@@ -48,34 +48,34 @@ class GitlabProjects ...@@ -48,34 +48,34 @@ class GitlabProjects
def create_branch def create_branch
branch_name = ARGV.shift branch_name = ARGV.shift
ref = ARGV.shift || "HEAD" ref = ARGV.shift || "HEAD"
cmd = "cd #{full_path} && git branch #{branch_name} #{ref}" cmd = %W(git --git-dir=#{full_path} branch #{branch_name} #{ref})
system(cmd) system(*cmd)
end end
def rm_branch def rm_branch
branch_name = ARGV.shift branch_name = ARGV.shift
cmd = "cd #{full_path} && git branch -D #{branch_name}" cmd = %W(git --git-dir=#{full_path} branch -D #{branch_name})
system(cmd) system(*cmd)
end end
def create_tag def create_tag
tag_name = ARGV.shift tag_name = ARGV.shift
ref = ARGV.shift || "HEAD" ref = ARGV.shift || "HEAD"
cmd = "cd #{full_path} && git tag #{tag_name} #{ref}" cmd = %W(git --git-dir=#{full_path} tag #{tag_name} #{ref})
system(cmd) system(*cmd)
end end
def rm_tag def rm_tag
tag_name = ARGV.shift tag_name = ARGV.shift
cmd = "cd #{full_path} && git tag -d #{tag_name}" cmd = %W(git --git-dir=#{full_path} tag -d #{tag_name})
system(cmd) system(*cmd)
end end
def add_project def add_project
$logger.info "Adding project #{@project_name} at <#{full_path}>." $logger.info "Adding project #{@project_name} at <#{full_path}>."
FileUtils.mkdir_p(full_path, mode: 0770) FileUtils.mkdir_p(full_path, mode: 0770)
cmd = "cd #{full_path} && git init --bare" cmd = %W(git --git-dir=#{full_path} init --bare)
system(cmd) && create_hooks(full_path) system(*cmd) && create_hooks(full_path)
end end
def create_hooks(path) def create_hooks(path)
...@@ -94,8 +94,8 @@ class GitlabProjects ...@@ -94,8 +94,8 @@ class GitlabProjects
def import_project def import_project
@source = ARGV.shift @source = ARGV.shift
$logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>." $logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>."
cmd = "cd #{repos_path} && git clone --bare #{@source} #{project_name}" cmd = %W(git clone --bare #{@source} #{project_name})
system(cmd) && create_hooks(full_path) system(*cmd, chdir: repos_path) && create_hooks(full_path)
end end
# Move repository from one directory to another # Move repository from one directory to another
...@@ -156,8 +156,8 @@ class GitlabProjects ...@@ -156,8 +156,8 @@ class GitlabProjects
end end
$logger.info "Forking project from <#{full_path}> to <#{full_destination_path}>." $logger.info "Forking project from <#{full_path}> to <#{full_destination_path}>."
cmd = "cd #{namespaced_path} && git clone --bare #{full_path}" cmd = %W(git clone --bare #{full_path})
system(cmd) && create_hooks(full_destination_path) system(*cmd, chdir: namespaced_path) && create_hooks(full_destination_path)
end end
def update_head def update_head
......
...@@ -101,8 +101,8 @@ describe GitlabProjects do ...@@ -101,8 +101,8 @@ describe GitlabProjects do
end end
it "should receive valid cmd" do it "should receive valid cmd" do
valid_cmd = "cd #{tmp_repo_path} && git init --bare" valid_cmd = ['git', "--git-dir=#{tmp_repo_path}", 'init', '--bare']
gl_projects.should_receive(:system).with(valid_cmd).and_return(true) gl_projects.should_receive(:system).with(*valid_cmd).and_return(true)
gl_projects.should_receive(:create_hooks).with(tmp_repo_path) gl_projects.should_receive(:create_hooks).with(tmp_repo_path)
gl_projects.exec gl_projects.exec
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment