summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-09-15 10:17:14 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-09-19 17:05:23 +0100
commit2f94bc3ecae26612a392f35e821db2976856e2cd (patch)
treef4fb290fb4eb78f712fc8258edf800e6ab49a25d
parent2b575a8d646aa0dc45db6b8a371c7f6648f2ad69 (diff)
downloadgitlab-shell-add-force-push-option-to-push-branches.tar.gz
Adds --force option to push branches.add-force-push-option-to-push-branches
-rw-r--r--CHANGELOG3
-rw-r--r--lib/gitlab_projects.rb7
-rw-r--r--spec/gitlab_projects_spec.rb12
3 files changed, 21 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 43d2612..fdeb753 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v5.9.1
+ - Adds --force option to push branches
+
v5.9.0
- Support new /internal/pre-receive API endpoint for post-receive operations
- Support new /internal/post-receive API endpoint for post-receive operations
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index 49a1d25..9586345 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -116,8 +116,13 @@ class GitlabProjects
# timeout for push
timeout = (ARGV.shift || 120).to_i
+ # push with --force?
+ forced = ARGV.delete('--force') if ARGV.include?('--force')
+
$logger.info "Pushing branches from #{full_path} to remote #{remote_name}: #{ARGV}"
- cmd = %W(git --git-dir=#{full_path} push -- #{remote_name}).concat(ARGV)
+ cmd = %W(git --git-dir=#{full_path} push)
+ cmd << forced if forced
+ cmd += %W(-- #{remote_name}).concat(ARGV)
pid = Process.spawn(*cmd)
begin
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index 2220ee4..ffba3d4 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -313,6 +313,18 @@ describe GitlabProjects do
expect(gl_projects.exec).to be false
end
+
+ context 'with --force' do
+ let(:cmd) { %W(git --git-dir=#{full_path} push --force -- #{remote_name} #{branch_name}) }
+ let(:gl_projects) { build_gitlab_projects('push-branches', repos_path, project_name, remote_name, '600', '--force', 'master') }
+
+ it 'executes the command' do
+ expect(Process).to receive(:spawn).with(*cmd).and_return(pid)
+ expect(Process).to receive(:wait).with(pid)
+
+ expect(gl_projects.exec).to be true
+ end
+ end
end
describe :fetch_remote do