Skip to content

Commit 642e4f2

Browse files
theuniRandyMcMillan
authored andcommitted
verify-commits: error and exit cleanly when git is too old.
1 parent 5cbfab4 commit 642e4f2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

contrib/verify-commits/verify-commits.py

+14-1
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)