Skip to content

Commit 7045d8a

Browse files
Adding :track => <branch_name> and :fetch => true option to add_remote
Adding tests too closes ruby-git#40
1 parent ff2f09f commit 7045d8a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/git/base.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ def remotes
337337
# @git.fetch('scotts_git')
338338
# @git.merge('scotts_git/master')
339339
#
340+
# Options:
341+
# :fetch => true
342+
# :track => <branch_name>
340343
def add_remote(name, url, opts = {})
341344
url = url.repo.path if url.is_a?(Git::Base)
342345
self.lib.remote_add(name, url, opts)

lib/git/lib.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ def conflicts # :yields: file, your, their
528528

529529
def remote_add(name, url, opts = {})
530530
arr_opts = ['add']
531-
arr_opts << '-f' if opts[:with_fetch]
532-
arr_opts << '-t' << opts[:with_track] if opts[:with_track]
531+
arr_opts << '-f' if opts[:with_fetch] || opts[:fetch]
532+
arr_opts << '-t' << opts[:track] if opts[:track]
533533
arr_opts << '--'
534534
arr_opts << name
535535
arr_opts << url

tests/units/test_remotes.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ class TestRemotes < Test::Unit::TestCase
66
def setup
77
set_file_paths
88
end
9+
10+
def test_add_remote
11+
in_temp_dir do |path|
12+
local = Git.clone(@wbare, 'local')
13+
remote = Git.clone(@wbare, 'remote')
14+
15+
local.add_remote('testremote', remote)
16+
17+
assert(!local.branches.map{|b| b.full}.include?('testremote/master'))
18+
19+
local.add_remote('testremote2', remote, :fetch => true)
20+
21+
assert(local.branches.map{|b| b.full}.include?('remotes/testremote2/master'))
22+
23+
local.add_remote('testremote3', remote, :track => 'master')
24+
25+
assert(local.branches.map{|b| b.full}.include?('master')) #We actually a new branch ('test_track') on the remote and track that one intead.
26+
end
27+
end
928

1029
def test_remote_fun
1130
in_temp_dir do |path|

0 commit comments

Comments
 (0)