diff --git a/README.md b/README.md index 7dc5682c..87d1d5cf 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ And here are the operations that will need to write to your git repository. g.fetch g.fetch(g.remotes.first) + g.fetch('origin', {:ref => 'some/ref/head'} ) g.pull g.pull(Git::Repo, Git::Branch) # fetch and a merge diff --git a/lib/git/lib.rb b/lib/git/lib.rb index c0d0fd56..0b3307fc 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -738,6 +738,7 @@ def tag(name, *opts) def fetch(remote, opts) arr_opts = [remote] + arr_opts << opts[:ref] if opts[:ref] arr_opts << '--tags' if opts[:t] || opts[:tags] arr_opts << '--prune' if opts[:p] || opts[:prune] diff --git a/tests/units/test_remotes.rb b/tests/units/test_remotes.rb index 1b9a7892..3e90c3b5 100644 --- a/tests/units/test_remotes.rb +++ b/tests/units/test_remotes.rb @@ -122,6 +122,34 @@ def test_fetch assert(loc.tags.map(&:name).include?('test-tag-in-deleted-branch')) end end + + def test_fetch_ref_adds_ref_option + in_temp_dir do |path| + loc = Git.clone(@wbare, 'local') + rem = Git.clone(@wbare, 'remote', :config => 'receive.denyCurrentBranch=ignore') + loc.add_remote('testrem', rem) + + loc.chdir do + new_file('test-file1', 'gonnaCommitYou') + loc.add + loc.commit('master commit 1') + first_commit_sha = loc.log.first.sha + + new_file('test-file2', 'gonnaCommitYouToo') + loc.add + loc.commit('master commit 2') + second_commit_sha = loc.log.first.sha + + # Make sure fetch message only has the first commit when we fetch the first commit + assert(loc.fetch('origin', {:ref => first_commit_sha}).include?(first_commit_sha)) + assert(!loc.fetch('origin', {:ref => first_commit_sha}).include?(second_commit_sha)) + + # Make sure fetch message only has the second commit when we fetch the second commit + assert(loc.fetch('origin', {:ref => second_commit_sha}).include?(second_commit_sha)) + assert(!loc.fetch('origin', {:ref => second_commit_sha}).include?(first_commit_sha)) + end + end + end def test_push in_temp_dir do |path|