summaryrefslogtreecommitdiff
path: root/lib/gitlab_projects.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-10 19:32:30 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-10 19:32:30 +0300
commit488a0340fa608af34c36deeba11d4e7192c260bd (patch)
treeb4496127876dd943ff96ae713696aa71fd0d7eda /lib/gitlab_projects.rb
parent79c58482962bd7ddd4979a4afcd178f697fe84fa (diff)
downloadgitlab-shell-488a0340fa608af34c36deeba11d4e7192c260bd.tar.gz
Update head feature
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r--lib/gitlab_projects.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index e60438e..8c280ea 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -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