diff options
author | Andrew Chow <github@achow101.com> | 2023-04-14 09:26:55 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-04-14 09:27:11 -0400 |
commit | 69460bd8bc56762513b20218b9839c2ae4c40aaf (patch) | |
tree | afc8053da25e39d90f79174d0aee6f686cf3eb0d | |
parent | 2bfe43db164de7382d01c06dbdebf250d35f9f2f (diff) | |
parent | 1fefcf27edcac7ebb87c1d3c68bcd9870e3ae78a (diff) |
Merge bitcoin/bitcoin#27461: verify-commits: error and exit cleanly when git is too old.
1fefcf27edcac7ebb87c1d3c68bcd9870e3ae78a 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](https://github.com/git/git/commit/1f0c3a29da3515d88537902cd267cc726020eea5).
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 https://github.com/bitcoin/bitcoin/pull/27461/commits/1fefcf27edcac7ebb87c1d3c68bcd9870e3ae78a
achow101:
ACK 1fefcf27edcac7ebb87c1d3c68bcd9870e3ae78a
Tree-SHA512: f3dc583edf6ff6ff9bf06f33de967e10b8423ce62e7370912ffdca8a4ca4bfe4c2e783e9ad76281ce9e6748a4643d187aa5cb4a6b9ec4c1582910f02b94b6e3c
-rwxr-xr-x | contrib/verify-commits/verify-commits.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/contrib/verify-commits/verify-commits.py b/contrib/verify-commits/verify-commits.py index f301964280..a1fe78a643 100755 --- a/contrib/verify-commits/verify-commits.py +++ b/contrib/verify-commits/verify-commits.py @@ -178,7 +178,20 @@ def main(): allow_unclean = current_commit in unclean_merge_allowed if len(parents) == 2 and check_merge and not allow_unclean: current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit]).decode('utf8').splitlines()[0] - recreated_tree = subprocess.check_output([GIT, "merge-tree", parents[0], parents[1]]).decode('utf8').splitlines()[0] + + # This merge-tree functionality requires git >= 2.38. The + # --write-tree option was added in order to opt-in to the new + # behavior. Older versions of git will not recognize the option and + # will instead exit with code 128. + try: + recreated_tree = subprocess.check_output([GIT, "merge-tree", "--write-tree", parents[0], parents[1]]).decode('utf8').splitlines()[0] + except subprocess.CalledProcessError as e: + if e.returncode == 128: + print("git v2.38+ is required for this functionality.", file=sys.stderr) + sys.exit(1) + else: + raise e + if current_tree != recreated_tree: print("Merge commit {} is not clean".format(current_commit), file=sys.stderr) subprocess.call([GIT, 'diff', recreated_tree, current_tree]) |