Skip to content

Commit ba1df97

Browse files
authored
Merge branch 'master' into 355
2 parents 3ad8851 + d5b0ec0 commit ba1df97

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
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/diff.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ def process_full_diff
127127
}
128128
final = {}
129129
current_file = nil
130-
full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", {
131-
:invalid => :replace,
132-
:undef => :replace
133-
})
130+
if @full_diff.encoding.name != "UTF-8"
131+
full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", { :invalid => :replace, :undef => :replace })
132+
else
133+
full_diff_utf8_encoded = @full_diff
134+
end
134135
full_diff_utf8_encoded.split("\n").each do |line|
135136
if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line)
136137
current_file = m[1]

lib/git/lib.rb

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

731731
def fetch(remote, opts)
732732
arr_opts = [remote]
733+
arr_opts << opts[:ref] if opts[:ref]
733734
arr_opts << '--tags' if opts[:t] || opts[:tags]
734735
arr_opts << '--prune' if opts[:p] || opts[:prune]
735736

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)