Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions scripts/vale/changed_lines_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
def get_changed_files(base_sha, head_sha, pattern=r'^docs/.*\.(md|mdx)$'):
"""Get list of changed files matching the pattern."""
try:
cmd = f"git diff --name-only {base_sha} {head_sha}"
# Three-dot diff (base...head) scopes the comparison to the changes
# the PR branch added since it diverged from base. Two-dot or
# endpoint form would also surface commits main has gained since
# the branch was created, causing Vale to run on unrelated files.
cmd = f"git diff --name-only {base_sha}...{head_sha}"
result = subprocess.check_output(cmd, shell=True, text=True)
all_files = result.splitlines()

Expand All @@ -45,7 +49,7 @@ def get_changed_files(base_sha, head_sha, pattern=r'^docs/.*\.(md|mdx)$'):
def get_changed_lines(file_path, base_sha, head_sha):
"""Get line numbers that were changed in a specific file."""
try:
cmd = f"git diff --unified=0 {base_sha} {head_sha} -- {file_path}"
cmd = f"git diff --unified=0 {base_sha}...{head_sha} -- {file_path}"
diff_output = subprocess.check_output(cmd, shell=True, text=True)

changed_lines = []
Expand Down
Loading