Skip to content

Commit 77376b6

Browse files
committed
[update-checkout] Gracefully degrade time match.
Previously, when invoking the script with match-timestamp, if the refspec was absent, the find_rev_by_timestamp function would throw an exception and the script would hang forever. Here, it is first checked via `git rev-parse --verify $REFSPEC` that the refspec actually exists in the target repo. If it does not, the refspec is just omitted from the command, giving the latest commit before the currently checked out one.
1 parent bb67d1e commit 77376b6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,15 @@ def confirm_tag_in_repo(tag, repo_name) -> Optional[str]:
100100

101101

102102
def find_rev_by_timestamp(timestamp, repo_name, refspec):
103+
refspec_exists = True
104+
try:
105+
shell.run(["git", "rev-parse", "--verify", refspec])
106+
except Exception:
107+
refspec_exists = False
103108
args = ["git", "log", "-1", "--format=%H", "--first-parent",
104-
'--before=' + timestamp, refspec]
109+
'--before=' + timestamp]
110+
if refspec_exists:
111+
args.append(refspec)
105112
rev = shell.capture(args).strip()
106113
if rev:
107114
return rev

0 commit comments

Comments
 (0)