As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 488a0340 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Update head feature

parent 79c58482
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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'
Loading
Loading
@@ -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)
Loading
Loading
@@ -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
Loading
Loading
@@ -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') }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment