mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 05:57:59 +01:00
Merge bitcoin/bitcoin#29660: lint: Fix COMMIT_RANGE issues
fa1146d01blint: Fix COMMIT_RANGE issues (MarcoFalke) Pull request description: `COMMIT_RANGE` has problems on forks or local branches: * When `LOCAL_BRANCH` is set, it assumes the presence of a `master` branch, and that the `master` branch is up-to-date. Both of which may be false. (See also discussion in https://github.com/bitcoin/bitcoin/pull/29274#discussion_r1504226422) * When `COMMIT_RANGE` isn't set in `lint-git-commit-check.py`, and `--prev-commits` isn't set either, it has the same (broken) assumptions. Fix all issues by simply assuming a merge commit exists. This allows to drop `LOCAL_BRANCH`. It also allows to drop `SKIP_EMPTY_NOT_A_PR`, because scripts will already skip an empty range. Finally, it allows to drop `--prev-commits n`, because one can simply say `COMMIT_RANGE='HEAD~n..HEAD'` to achieve the same. ACKs for top commit: Sjors: tACKfa1146d01bTree-SHA512: f1477a38267fd4fdb8d396211a5d6bed5f418798c7edaba43487957aaf726cd45244ccf15187b3dd896d398fa1df3fe0a37323e49cf44d60a2018786ed41e5ba
This commit is contained in:
@@ -23,31 +23,18 @@ def parse_args():
|
||||
""",
|
||||
epilog=f"""
|
||||
You can manually set the commit-range with the COMMIT_RANGE
|
||||
environment variable (e.g. "COMMIT_RANGE='47ba2c3...ee50c9e'
|
||||
{sys.argv[0]}"). Defaults to current merge base when neither
|
||||
prev-commits nor the environment variable is set.
|
||||
environment variable (e.g. "COMMIT_RANGE='HEAD~n..HEAD'
|
||||
{sys.argv[0]}") for the last 'n' commits.
|
||||
""")
|
||||
|
||||
parser.add_argument("--prev-commits", "-p", required=False, help="The previous n commits to check")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
parse_args()
|
||||
exit_code = 0
|
||||
|
||||
if not os.getenv("COMMIT_RANGE"):
|
||||
if args.prev_commits:
|
||||
commit_range = "HEAD~" + args.prev_commits + "...HEAD"
|
||||
else:
|
||||
# This assumes that the target branch of the pull request will be master.
|
||||
merge_base = check_output(["git", "merge-base", "HEAD", "master"], text=True, encoding="utf8").rstrip("\n")
|
||||
commit_range = merge_base + "..HEAD"
|
||||
else:
|
||||
commit_range = os.getenv("COMMIT_RANGE")
|
||||
if commit_range == "SKIP_EMPTY_NOT_A_PR":
|
||||
sys.exit(0)
|
||||
assert os.getenv("COMMIT_RANGE") # E.g. COMMIT_RANGE='HEAD~n..HEAD'
|
||||
commit_range = os.getenv("COMMIT_RANGE")
|
||||
|
||||
commit_hashes = check_output(["git", "log", commit_range, "--format=%H"], text=True, encoding="utf8").splitlines()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user