Commit 488a0340 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Update head feature

parent 79c58482
......@@ -17,6 +17,8 @@ require_relative '../lib/gitlab_init'
#
# /bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
#
# /bin/gitlab-projects update-head gitlab/gitlab-ci.git 5-2-stable
#
require File.join(ROOT_PATH, 'lib', 'gitlab_projects')
# Return non-zero if command execution was not successful
......
......@@ -31,6 +31,7 @@ class GitlabProjects
when 'mv-project'; mv_project
when 'import-project'; import_project
when 'fork-project'; fork_project
when 'update-head'; update_head
else
$logger.warn "Attempt to execute invalid gitlab-projects command #{@command.inspect}."
puts 'not allowed'
......@@ -127,6 +128,27 @@ class GitlabProjects
system(cmd)
end
def update_head
new_head = ARGV.shift
unless new_head
$logger.error "update-head failed: no branch provided."
return false
end
unless File.exists?(File.join(full_path, 'refs/heads', new_head))
$logger.error "update-head failed: specified branch does not exist in ref/heads."
return false
end
File.open(File.join(full_path, 'HEAD'), 'w') do |f|
f.write("ref: refs/heads/#{new_head}")
end
$logger.info "Update head in project #{project_name} to <#{new_head}>."
true
end
private
def create_hooks_to(dest_path)
......@@ -135,5 +157,4 @@ class GitlabProjects
"ln -s #{pr_hook_path} #{dest_path}/hooks/post-receive && ln -s #{up_hook_path} #{dest_path}/hooks/update"
end
end
......@@ -106,6 +106,27 @@ describe GitlabProjects do
end
end
describe :update_head do
let(:gl_projects) { build_gitlab_projects('update-head', repo_name, 'stable') }
before do
FileUtils.mkdir_p(tmp_repo_path)
system("git init --bare #{tmp_repo_path}")
system("touch #{tmp_repo_path}/refs/heads/stable")
File.read(File.join(tmp_repo_path, 'HEAD')).strip.should == 'ref: refs/heads/master'
end
it "should update head for repo" do
gl_projects.exec.should be_true
File.read(File.join(tmp_repo_path, 'HEAD')).strip.should == 'ref: refs/heads/stable'
end
it "should log an update_head event" do
$logger.should_receive(:info).with("Update head in project #{repo_name} to <stable>.")
gl_projects.exec
end
end
describe :import_project do
let(:gl_projects) { build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git') }
......
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