Skip to content

Commit 3880fff

Browse files
achow101backport
authored andcommitted
Merge 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@1fefcf2 achow101: ACK 1fefcf2 Tree-SHA512: f3dc583edf6ff6ff9bf06f33de967e10b8423ce62e7370912ffdca8a4ca4bfe4c2e783e9ad76281ce9e6748a4643d187aa5cb4a6b9ec4c1582910f02b94b6e3c
1 parent 54e2588 commit 3880fff

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

contrib/verify-commits/verify-commits.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,20 @@ def main():
148148
allow_unclean = current_commit in unclean_merge_allowed
149149
if len(parents) == 2 and check_merge and not allow_unclean:
150150
current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit]).decode('utf8').splitlines()[0]
151-
subprocess.call([GIT, 'checkout', '--force', '--quiet', parents[0]])
152-
subprocess.call([GIT, 'merge', '--no-ff', '--quiet', '--no-gpg-sign', parents[1]], stdout=subprocess.DEVNULL)
153-
recreated_tree = subprocess.check_output([GIT, 'show', '--format=format:%T', 'HEAD']).decode('utf8').splitlines()[0]
151+
152+
# This merge-tree functionality requires git >= 2.38. The
153+
# --write-tree option was added in order to opt-in to the new
154+
# behavior. Older versions of git will not recognize the option and
155+
# will instead exit with code 128.
156+
try:
157+
recreated_tree = subprocess.check_output([GIT, "merge-tree", "--write-tree", parents[0], parents[1]]).decode('utf8').splitlines()[0]
158+
except subprocess.CalledProcessError as e:
159+
if e.returncode == 128:
160+
print("git v2.38+ is required for this functionality.", file=sys.stderr)
161+
sys.exit(1)
162+
else:
163+
raise e
164+
154165
if current_tree != recreated_tree:
155166
print("Merge commit {} is not clean".format(current_commit), file=sys.stderr)
156167
subprocess.call([GIT, 'diff', current_commit])

0 commit comments

Comments
 (0)