Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
28 changes: 28 additions & 0 deletions tests/units/test_remotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down