Skip to content

Commit

Permalink
Add option to push all branches to a remote repo at one time (#678)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Grant <chrisgrant@resoluteoil.com>
Co-authored-by: Chris Grant <chrisgrant@resoluteoil.com>
  • Loading branch information
interhive and gfzdw committed Dec 28, 2023
1 parent b0d89ac commit 3bdb280
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -345,6 +345,9 @@ g.push(g.remote('name'))
# delete remote branch
g.push('origin', 'remote_branch_name', force: true, delete: true)

# push all branches to remote at one time
g.push('origin', all: true)

g.worktree('/tmp/new_worktree').add
g.worktree('/tmp/new_worktree', 'branch1').add
g.worktree('/tmp/new_worktree').remove
Expand Down
4 changes: 3 additions & 1 deletion lib/git/lib.rb
Expand Up @@ -972,7 +972,9 @@ def push(remote = nil, branch = nil, opts = nil)
arr_opts = []
arr_opts << '--mirror' if opts[:mirror]
arr_opts << '--delete' if opts[:delete]
arr_opts << '--force' if opts[:force] || opts[:f]
arr_opts << '--force' if opts[:force] || opts[:f]
arr_opts << '--all' if opts[:all] && remote

Array(opts[:push_option]).each { |o| arr_opts << '--push-option' << o } if opts[:push_option]
arr_opts << remote if remote
arr_opts_with_branch = arr_opts.dup
Expand Down
7 changes: 7 additions & 0 deletions tests/units/test_push.rb
Expand Up @@ -96,6 +96,13 @@ class TestPush < Test::Unit::TestCase
assert_command_line(expected_command_line, git_cmd, git_cmd_args)
end

test 'push with all: true' do
expected_command_line = ['push', '--all', 'origin']
git_cmd = :push
git_cmd_args = ['origin', all: true]
assert_command_line(expected_command_line, git_cmd, git_cmd_args)
end

test 'when push succeeds an error should not be raised' do
in_temp_dir do
Git.init('remote.git', initial_branch: 'master', bare: true)
Expand Down

0 comments on commit 3bdb280

Please sign in to comment.