Skip to content

Commit dbfcb40

Browse files
Merge branch 'master' of github.com:schacon/ruby-git
2 parents 7d67046 + f54809d commit dbfcb40

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

lib/git/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ def checkout_file(version, file)
332332

333333
# fetches changes from a remote branch - this does not modify the working directory,
334334
# it just gets the changes from the remote if there are any
335-
def fetch(remote = 'origin')
336-
self.lib.fetch(remote)
335+
def fetch(remote = 'origin', opts={})
336+
self.lib.fetch(remote, opts)
337337
end
338338

339339
# pushes changes to a remote repository - easiest if this is a cloned repository,

lib/git/lib.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,16 +607,19 @@ def tag(name, *opts)
607607
end
608608

609609

610-
def fetch(remote)
611-
command('fetch', remote)
610+
def fetch(remote, opts)
611+
arr_opts = [remote]
612+
arr_opts << '--tags' if opts[:t] || opts[:tags]
613+
614+
command('fetch', arr_opts)
612615
end
613616

614617
def push(remote, branch = 'master', opts = {})
615618
# Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
616619
opts = {:tags => opts} if [true, false].include?(opts)
617620

618621
arr_opts = []
619-
arr_opts << '--f' if opts[:force] || opts[:f]
622+
arr_opts << '--force' if opts[:force] || opts[:f]
620623
arr_opts << remote
621624

622625
command('push', arr_opts + [branch])

lib/git/remote.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def initialize(base, name)
1111
@fetch_opts = config['fetch']
1212
end
1313

14-
def fetch
15-
@base.fetch(@name)
14+
def fetch(opts={})
15+
@base.fetch(@name, opts)
1616
end
1717

1818
# merge this remote locally

tests/units/test_remotes.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ def test_remote_fun
8080
#puts loc.remotes.inspect
8181
end
8282
end
83+
84+
def test_fetch
85+
in_temp_dir do |path|
86+
loc = Git.clone(@wbare, 'local')
87+
rem = Git.clone(@wbare, 'remote')
88+
89+
r = loc.add_remote('testrem', rem)
90+
91+
Dir.chdir('remote') do
92+
rem.branch('testbranch').in_branch('tb commit') do
93+
new_file('test-file', 'add file')
94+
rem.add
95+
true
96+
end
97+
rem.branch('testbranch').in_branch do
98+
rem.add_tag('test-tag-in-deleted-branch')
99+
false
100+
end
101+
rem.branch('testbranch').delete
102+
end
103+
104+
r.fetch
105+
assert(!loc.tags.map(&:name).include?('test-tag-in-deleted-branch'))
106+
r.fetch :tags => true
107+
assert(loc.tags.map(&:name).include?('test-tag-in-deleted-branch'))
108+
end
109+
end
83110

84111
def test_push
85112
in_temp_dir do |path|

0 commit comments

Comments
 (0)