Skip to content

Commit 14c91e2

Browse files
authored
Merge pull request #43 from square/segiddins/retry-and-blow-away-cache-when-reading-tree-fails
Blow away cache and retry when reading tree fails after clone
2 parents f3c799f + c80b23a commit 14c91e2

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
git-fastclone (1.2.6)
4+
git-fastclone (1.2.7)
55
colorize
66
terrapin (~> 0.6.0)
77

lib/git-fastclone.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ def with_git_mirror(url)
358358
/fatal: packed object [a-z0-9]+ \(stored in .*?\) is corrupt/,
359359
/fatal: pack has \d+ unresolved delta/,
360360
'error: unable to read sha1 file of ',
361-
'fatal: did not receive expected object'
361+
'fatal: did not receive expected object',
362+
/^fatal: unable to read tree [a-z0-9]+\n^warning: Clone succeeded, but checkout failed/
362363
]
363364
if e.to_s =~ /^STDERR:\n.+^#{Regexp.union(error_strings)}/m
364365
# To avoid corruption of the cache, if we failed to update or check out we remove

lib/git-fastclone/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Version string for git-fastclone
44
module GitFastCloneVersion
5-
VERSION = '1.2.6'.freeze
5+
VERSION = '1.2.7'.freeze
66
end

spec/git_fastclone_runner_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
expect(yielded).to eq([test_url_valid])
307307
end
308308

309-
it 'should retry when the clone succeeds but checkout fails' do
309+
it 'should retry when the clone succeeds but checkout fails with corrupt packed object' do
310310
allow(subject).to receive(:update_reference_repo) {}
311311
expect(subject).to receive(:reference_repo_dir)
312312
expect(subject).to receive(:reference_repo_lock_file).and_return(lockfile)
@@ -333,6 +333,35 @@
333333
expect(yielded).to eq([test_url_valid])
334334
end
335335

336+
it 'should retry when the clone succeeds but checkout fails with unable to read tree' do
337+
allow(subject).to receive(:update_reference_repo) {}
338+
expect(subject).to receive(:reference_repo_dir)
339+
expect(subject).to receive(:reference_repo_lock_file).and_return(lockfile)
340+
341+
responses = [
342+
lambda { |_url|
343+
raise Terrapin::ExitStatusError, <<-ERROR.gsub(/^ {12}/, '')
344+
STDOUT:
345+
346+
STDERR:
347+
348+
error: Could not read 92cf57b8f07df010ab5f607b109c325e30e46235
349+
fatal: unable to read tree 0c32c0521d3b0bfb4e74e4a39b97a84d1a3bb9a1
350+
warning: Clone succeeded, but checkout failed.
351+
You can inspect what was checked out with 'git status'
352+
and retry with 'git restore --source=HEAD :/'
353+
ERROR
354+
},
355+
->(url) { url }
356+
]
357+
subject.with_git_mirror(test_url_valid) do
358+
yielded << responses.shift.call(test_url_valid)
359+
end
360+
361+
expect(responses).to be_empty
362+
expect(yielded).to eq([test_url_valid])
363+
end
364+
336365
it 'should retry when one delta is missing' do
337366
allow(subject).to receive(:update_reference_repo) {}
338367
expect(subject).to receive(:reference_repo_dir)

0 commit comments

Comments
 (0)