Skip to content

Commit fe49ca8

Browse files
committed
Retry git ls-remote failures
1 parent 6a0bc09 commit fe49ca8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

bin/git-sync-check.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module Git
1010
# cgit bare repository
1111
GIT_DIR = '/var/git/ruby.git'
1212

13+
# This is retried because ls-remote of GitHub sometimes fails
14+
Error = Class.new(StandardError)
15+
1316
class << self
1417
def show_ref
1518
git('show-ref')
@@ -24,7 +27,7 @@ def ls_remote(remote)
2427
def git(*cmd)
2528
out = IO.popen({ 'GIT_DIR' => GIT_DIR }, ['git', *cmd], &:read)
2629
unless $?.success?
27-
raise "Failed to execute: git #{cmd.join(' ')}"
30+
raise Git::Error.new("Failed to execute: git #{cmd.join(' ')}")
2831
end
2932
out
3033
end
@@ -134,6 +137,14 @@ def self.check_consistency
134137
end
135138
Slack.notify(message)
136139
puts message
140+
rescue Git::Error => e
141+
attempts -= 1
142+
if attempts > 0
143+
puts "Retrying #{e.class}: #{e.message} (remaining attempts: #{attempts})"
144+
sleep 5
145+
retry
146+
end
147+
Slack.notify("#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}")
137148
rescue => e
138149
Slack.notify("#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}")
139150
end

0 commit comments

Comments
 (0)