Skip to content

Commit 47fbd43

Browse files
author
Justin Martin
authored
Merge pull request square#39 from square/jmartin/unable-to-read-sha1-error
Clear the cache on an 'unable to read sha1' error
2 parents a6f8a06 + a4e474a commit 47fbd43

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
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.3)
4+
git-fastclone (1.2.4)
55
colorize
66
terrapin (~> 0.6.0)
77

lib/git-fastclone.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,13 @@ def with_git_mirror(url)
353353
yield dir
354354
rescue Terrapin::ExitStatusError => e
355355
error_strings = [
356-
'missing blob object',
357-
'remote did not send all necessary objects',
358-
/packed object [a-z0-9]+ \(stored in .*?\) is corrupt/,
359-
/pack has \d+ unresolved deltas/
356+
'fatal: missing blob object',
357+
'fatal: remote did not send all necessary objects',
358+
/fatal: packed object [a-z0-9]+ \(stored in .*?\) is corrupt/,
359+
/fatal: pack has \d+ unresolved deltas/,
360+
'error: unable to read sha1 file of '
360361
]
361-
if e.to_s =~ /^STDERR:\n.+^fatal: #{Regexp.union(error_strings)}/m
362+
if e.to_s =~ /^STDERR:\n.+^#{Regexp.union(error_strings)}/m
362363
# To avoid corruption of the cache, if we failed to update or check out we remove
363364
# the cache directory entirely. This may cause the current clone to fail, but if the
364365
# underlying error from git is transient it will not affect future clones.

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.3'.freeze
5+
VERSION = '1.2.4'.freeze
66
end

spec/git_fastclone_runner_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,33 @@
360360
expect(yielded).to eq([test_url_valid])
361361
end
362362
end
363+
364+
it 'should retry when the cache errors with unable to read sha1 file' do
365+
allow(subject).to receive(:update_reference_repo) {}
366+
expect(subject).to receive(:reference_repo_dir)
367+
expect(subject).to receive(:reference_repo_lock_file).and_return(lockfile)
368+
369+
responses = [
370+
lambda { |_url|
371+
raise Terrapin::ExitStatusError, <<-ERROR.gsub(/^ {12}/, '')
372+
STDOUT:
373+
374+
STDERR:
375+
376+
error: unable to read sha1 file of sqiosbuild/lib/action/action.rb (6113b739af82d8b07731de8a58d6e233301f80ab)
377+
fatal: unable to checkout working tree
378+
warning: Clone succeeded, but checkout failed.
379+
You can inspect what was checked out with 'git status'
380+
and retry with 'git restore --source=HEAD :/'
381+
ERROR
382+
},
383+
->(url) { url }
384+
]
385+
subject.with_git_mirror(test_url_valid) do
386+
yielded << responses.shift.call(test_url_valid)
387+
end
388+
389+
expect(responses).to be_empty
390+
expect(yielded).to eq([test_url_valid])
391+
end
363392
end

0 commit comments

Comments
 (0)