diff --git a/bin/check_autogenerated_edits.py b/bin/check_autogenerated_edits.py index 732adcd1c..816e17d21 100755 --- a/bin/check_autogenerated_edits.py +++ b/bin/check_autogenerated_edits.py @@ -4,7 +4,9 @@ This script checks for unauthorized modifications in autogenerated sections of m It is designed to be used in a GitHub Actions workflow or a local pre-commit hook. Features: -- Detects markdown files changed between two commits (default last commit). +- Detects markdown files changed between a commit and one of its ancestors. Default is to + check the last commit only. When triggered on a pull request it should typically compare the + pull request branch head and its merge base - the commit on the main branch before it diverged. - Identifies modified autogenerated sections marked by specific comments. - Reports violations using GitHub Actions error messages. - Exits with a nonzero status code if unauthorized changes are found. @@ -24,14 +26,14 @@ def get_changed_files(base, head): """ Retrieve a list of markdown files that were changed between the base and head commits. """ - files = run_git(["diff", "--name-only", base, head]).splitlines() + files = run_git(["diff", "--name-only", f"{base}...{head}"]).splitlines() return [f for f in files if f.endswith(".md")] def get_diff(file, base, head): """ Get the diff of a given file between the base and head commits. """ - return run_git(["diff", "-U0", base, head, "--", file]).splitlines() + return run_git(["diff", "-U0", f"{base}...{head}", "--", file]).splitlines() def get_file_content(ref, file): """