Skip to content

Commit e7f1880

Browse files
taquitosperlun
authored andcommitted
Allow fetch operation to receive a ref param (ruby-git#362)
* Allow fetch operation to receive a `ref` param addresses ruby-git#361 * Update remote object * remove .ruby-version * Use options instead of separate param * Update for comments * Update for style
1 parent d1ab2c7 commit e7f1880

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ And here are the operations that will need to write to your git repository.
226226

227227
g.fetch
228228
g.fetch(g.remotes.first)
229+
g.fetch('origin', {:ref => 'some/ref/head'} )
229230

230231
g.pull
231232
g.pull(Git::Repo, Git::Branch) # fetch and a merge

lib/git/lib.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ def tag(name, *opts)
738738

739739
def fetch(remote, opts)
740740
arr_opts = [remote]
741+
arr_opts << opts[:ref] if opts[:ref]
741742
arr_opts << '--tags' if opts[:t] || opts[:tags]
742743
arr_opts << '--prune' if opts[:p] || opts[:prune]
743744

tests/units/test_remotes.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,34 @@ def test_fetch
122122
assert(loc.tags.map(&:name).include?('test-tag-in-deleted-branch'))
123123
end
124124
end
125+
126+
def test_fetch_ref_adds_ref_option
127+
in_temp_dir do |path|
128+
loc = Git.clone(@wbare, 'local')
129+
rem = Git.clone(@wbare, 'remote', :config => 'receive.denyCurrentBranch=ignore')
130+
loc.add_remote('testrem', rem)
131+
132+
loc.chdir do
133+
new_file('test-file1', 'gonnaCommitYou')
134+
loc.add
135+
loc.commit('master commit 1')
136+
first_commit_sha = loc.log.first.sha
137+
138+
new_file('test-file2', 'gonnaCommitYouToo')
139+
loc.add
140+
loc.commit('master commit 2')
141+
second_commit_sha = loc.log.first.sha
142+
143+
# Make sure fetch message only has the first commit when we fetch the first commit
144+
assert(loc.fetch('origin', {:ref => first_commit_sha}).include?(first_commit_sha))
145+
assert(!loc.fetch('origin', {:ref => first_commit_sha}).include?(second_commit_sha))
146+
147+
# Make sure fetch message only has the second commit when we fetch the second commit
148+
assert(loc.fetch('origin', {:ref => second_commit_sha}).include?(second_commit_sha))
149+
assert(!loc.fetch('origin', {:ref => second_commit_sha}).include?(first_commit_sha))
150+
end
151+
end
152+
end
125153

126154
def test_push
127155
in_temp_dir do |path|

0 commit comments

Comments
 (0)