Skip to content

Commit 4a1a7a3

Browse files
committed
Use merge base for lintdiff comparison instead of main tip
This ensures lintdiff only picks up files changed on the current branch, not files that changed on main since the branch point. Task: 001.md Co-authored-by: Isaac
1 parent 2705046 commit 4a1a7a3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

tools/lintdiff.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66
Drop in replacement for golangci-lint that runs it only on changed packages.
77
8-
Changes are calculated as diff against main by default, use --ref or -H/--head to change this.
8+
Changes are calculated as diff against the merge base with main by default, use --ref or -H/--head to change this.
99
"""
1010

1111
import os
@@ -42,10 +42,13 @@ def main():
4242
if gitroot:
4343
os.chdir(gitroot[0])
4444

45-
# Get list of changed files relative to repo root.
46-
# Note: Paths are always relative to repo root, even when running from subdirectories.
47-
# Example: Running from tools/ returns 'tools/lintdiff.py' rather than just 'lintdiff.py'.
48-
changed = parse_lines(["git", "diff", "--name-only", args.ref, "--", "."])
45+
# Resolve the merge base between the ref and HEAD so that we only lint
46+
# files changed on this branch, not files that changed on the ref since
47+
# the branch point.
48+
merge_base = parse_lines(["git", "merge-base", args.ref, "HEAD"])
49+
base = merge_base[0] if merge_base else args.ref
50+
51+
changed = parse_lines(["git", "diff", "--name-only", base, "--", "."])
4952

5053
cmd = args.args[:]
5154

0 commit comments

Comments
 (0)