diff options
author | Rubén Dávila <rdavila84@gmail.com> | 2016-03-21 15:14:23 -0500 |
---|---|---|
committer | Rubén Dávila <rdavila84@gmail.com> | 2016-03-21 15:14:23 -0500 |
commit | 42caddb2f60709e2e135f4e00f57277016a36898 (patch) | |
tree | 8d4b2c5fc6590a75438d8240ad7b443d80944db8 /lib/gitlab_projects.rb | |
parent | 9f482f8d24c8555ca4fbfd87efb1d155ed581509 (diff) | |
download | gitlab-shell-42caddb2f60709e2e135f4e00f57277016a36898.tar.gz |
Add new commands: push-branches and delete-remote-branches.
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r-- | lib/gitlab_projects.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index b3d6883..11a5a16 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -61,6 +61,8 @@ class GitlabProjects when 'fork-project'; fork_project when 'fetch-remote'; fetch_remote when 'update-head'; update_head + when 'push-branches'; push_branches + when 'delete-remote-branches'; delete_remote_branches when 'gc'; gc else $logger.warn "Attempt to execute invalid gitlab-projects command #{@command.inspect}." @@ -71,6 +73,47 @@ class GitlabProjects protected + def push_branches + remote_name = ARGV.shift + + $logger.info "Pushing branches from #{full_path} to remote #{remote_name}: #{ARGV}" + cmd = %W(git --git-dir=#{full_path} push --tags -- #{remote_name}).concat(ARGV) + pid = Process.spawn(*cmd) + + begin + Process.wait(pid) + + $?.exitstatus.zero? + rescue => exception + $logger.error "Pushing branches to remote #{remote_name} failed due to: #{exception.message}" + + Process.kill('KILL', pid) + Process.wait + false + end + end + + def delete_remote_branches + remote_name = ARGV.shift + branches = ARGV.map { |branch_name| ":#{branch_name}" } + + $logger.info "Pushing deleted branches from #{full_path} to remote #{remote_name}: #{ARGV}" + cmd = %W(git --git-dir=#{full_path} push -- #{remote_name}).concat(branches) + pid = Process.spawn(*cmd) + + begin + Process.wait(pid) + + $?.exitstatus.zero? + rescue => exception + $logger.error "Pushing deleted branches to remote #{remote_name} failed due to: #{exception.message}" + + Process.kill('KILL', pid) + Process.wait + false + end + end + def create_branch branch_name = ARGV.shift ref = ARGV.shift || "HEAD" |