Skip to content

Commit 69460bd

Browse files
committed
Merge bitcoin/bitcoin#27461: verify-commits: error and exit cleanly when git is too old.
1fefcf2 verify-commits: error and exit cleanly when git is too old. (Cory Fields) Pull request description: Requested by fanquake. Rather than failing with a cryptic error with older git, fail gracefully and mention why. The new option semantics [are explained here](git/git@1f0c3a2). Note: my local git versions are currently too old to test the new functionality, so I've only verified the failure case. ACKs for top commit: josibake: ACK bitcoin/bitcoin@1fefcf2 achow101: ACK 1fefcf2 Tree-SHA512: f3dc583edf6ff6ff9bf06f33de967e10b8423ce62e7370912ffdca8a4ca4bfe4c2e783e9ad76281ce9e6748a4643d187aa5cb4a6b9ec4c1582910f02b94b6e3c
2 parents 2bfe43d + 1fefcf2 commit 69460bd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

contrib/verify-commits/verify-commits.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,20 @@ def main():
178178
allow_unclean = current_commit in unclean_merge_allowed
179179
if len(parents) == 2 and check_merge and not allow_unclean:
180180
current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit]).decode('utf8').splitlines()[0]
181-
recreated_tree = subprocess.check_output([GIT, "merge-tree", parents[0], parents[1]]).decode('utf8').splitlines()[0]
181+
182+
# This merge-tree functionality requires git >= 2.38. The
183+
# --write-tree option was added in order to opt-in to the new
184+
# behavior. Older versions of git will not recognize the option and
185+
# will instead exit with code 128.
186+
try:
187+
recreated_tree = subprocess.check_output([GIT, "merge-tree", "--write-tree", parents[0], parents[1]]).decode('utf8').splitlines()[0]
188+
except subprocess.CalledProcessError as e:
189+
if e.returncode == 128:
190+
print("git v2.38+ is required for this functionality.", file=sys.stderr)
191+
sys.exit(1)
192+
else:
193+
raise e
194+
182195
if current_tree != recreated_tree:
183196
print("Merge commit {} is not clean".format(current_commit), file=sys.stderr)
184197
subprocess.call([GIT, 'diff', recreated_tree, current_tree])

0 commit comments

Comments
 (0)