Skip to content

Commit

Permalink
Add :push option to remote_set_url.
Browse files Browse the repository at this point in the history
This allows specifying, for example:

git.set_remote_url('upstream', 'git@github.com:foo/bar', push: true)
  • Loading branch information
p committed May 27, 2022
1 parent 6f2b3fd commit 2fea684
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/git/base.rb
Expand Up @@ -402,11 +402,14 @@ def add_remote(name, url, opts = {})
# sets the url for a remote
# url can be a git url or a Git::Base object if it's a local reference
#
# accepts options:
# :push
#
# @git.set_remote_url('scotts_git', 'git://repo.or.cz/rubygit.git')
#
def set_remote_url(name, url)
def set_remote_url(name, url, opts = {})
url = url.repo.path if url.is_a?(Git::Base)
self.lib.remote_set_url(name, url)
self.lib.remote_set_url(name, url, opts)
Git::Remote.new(self, name)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/git/lib.rb
Expand Up @@ -830,10 +830,13 @@ def remote_add(name, url, opts = {})
command('remote', arr_opts)
end

def remote_set_url(name, url)
# accepts options:
# :push
def remote_set_url(name, url, opts = {})
arr_opts = ['set-url']
arr_opts << name
arr_opts << url
arr_opts << '--push' if opts[:push]

command('remote', arr_opts)
end
Expand Down

0 comments on commit 2fea684

Please sign in to comment.