Skip to content

Commit b36b6fb

Browse files
Adding force(--f) support for the push command
closes ruby-git#113
1 parent 58fef2f commit b36b6fb

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/git/base.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ def fetch(remote = 'origin')
341341
#
342342
# @git.config('remote.remote-name.push', 'refs/heads/master:refs/heads/master')
343343
#
344-
def push(remote = 'origin', branch = 'master', tags = false)
345-
self.lib.push(remote, branch, tags)
344+
def push(remote = 'origin', branch = 'master', opts = {})
345+
# Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
346+
opts = {tags: opts} if [true, false].include?(opts)
347+
348+
self.lib.push(remote, branch, opts)
346349
end
347350

348351
# merges one or more branches into the current working branch

lib/git/lib.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,16 @@ def fetch(remote)
571571
command('fetch', remote)
572572
end
573573

574-
def push(remote, branch = 'master', tags = false)
575-
command('push', [remote, branch])
576-
command('push', ['--tags', remote]) if tags
574+
def push(remote, branch = 'master', opts = {})
575+
# Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
576+
opts = {tags: opts} if [true, false].include?(opts)
577+
578+
arr_opts = []
579+
arr_opts << '--f' if opts[:force] || opts[:f]
580+
arr_opts << remote
581+
582+
command('push', arr_opts + [branch])
583+
command('push', ['--tags'] + arr_opts) if opts[:tags]
577584
end
578585

579586
def pull(remote='origin', branch='master')

0 commit comments

Comments
 (0)