Skip to content

Commit 68d6cc6

Browse files
committed
Do not fetch already fetched commits
1 parent 29c7f84 commit 68d6cc6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tool/auto-style.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ def initialize(oldrev, newrev, branch = nil)
1515
@branch = branch
1616

1717
# GitHub may not fetch github.event.pull_request.base.sha at checkout
18-
git('fetch', '--depth=1', 'origin', @oldrev)
19-
git('fetch', '--depth=100', 'origin', @newrev)
18+
git('log', '--format=%H', '-1', @oldrev, out: IO::NULL, err: [:child, :out]) or
19+
git('fetch', '--depth=1', 'origin', @oldrev)
20+
git('log', '--format=%H', '-1', "#@newrev~99", out: IO::NULL, err: [:child, :out]) or
21+
git('fetch', '--depth=100', 'origin', @newrev)
2022

2123
with_clean_env do
2224
@revs = {}
@@ -66,12 +68,14 @@ def diff
6668

6769
private
6870

69-
def git(*args)
71+
def git(*args, **opts)
7072
cmd = ['git', *args].shelljoin
7173
puts "+ #{cmd}"
72-
unless with_clean_env { system('git', *args) }
74+
ret = with_clean_env { system('git', *args, **opts) }
75+
unless ret or opts[:err]
7376
abort "Failed to run: #{cmd}"
7477
end
78+
ret
7579
end
7680

7781
def with_clean_env

0 commit comments

Comments
 (0)