Skip to content

refactor(lint): use git-changed for --changed detection - #340

Merged
pyramation merged 1 commit into
mainfrom
feat/lint-git-changed
Aug 3, 2026
Merged

refactor(lint): use git-changed for --changed detection#340
pyramation merged 1 commit into
mainfrom
feat/lint-git-changed

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

src/changed.ts shipped its own copy of merge-base changed-file detection — default-branch discovery, porcelain parsing, rename arrows, existence filtering. That algorithm now lives in git-changed (0.3.0, zero runtime deps) and is shared with pgpm's bundle-drift check, so this file is the .sql filter over it and nothing else: ~120 lines → ~55, no child_process/fs/path imports left.

-const files = new Set(workingTreePaths(cwd));           // status --porcelain -uall, hand-parsed
-const mergeBase = tryGit(['merge-base', 'HEAD', base], cwd);
-for (const p of tryGit(['diff', '--name-only', '--diff-filter=ACMR', mergeBase, 'HEAD'], cwd)) …
-return { files: abs.filter(existsSync).sort(), base, mergeBase };
+const { paths, base, mergeBase } = gitChangedFiles({ cwd, base, ext });
+return { files: paths, base, mergeBase };

Public surface (resolveChangedBase, changedFiles, changedSqlFiles, ChangedFilesResult) and the CLI are unchanged, --changed semantics are unchanged, and the .sql filter is now ext: '.sql' inside the shared implementation rather than a .endsWith() afterwards.

One deliberate behaviour change. When $GITHUB_BASE_REF names a branch that resolves to no ref at all — neither origin/develop nor develop exists, i.e. a single-branch or shallow fetch — this used to return the bare develop anyway. Every later git call then rejected it and the gate silently degraded to working-tree changes, which in CI (where the branch's work is already committed) means it lints nothing and passes. git-changed only returns refs that resolve, so the base falls through to the repository's default branch and the gate still checks something. The test for that case is updated with the reasoning; the other 73 are untouched and pass.

74 tests green against the published git-changed@0.3.0, and --changed verified end-to-end on a scratch repo (an untracked .sql file is still found — that's the -uall behaviour this originally fixed).

Needs a publish for downstreams to get it, but nothing here changes what --changed does, so it can ride the next release rather than being pulled forward.

Link to Devin session: https://app.devin.ai/sessions/e84444b40007481e9de0285d8b5340b6
Requested by: @pyramation

@pyramation pyramation self-assigned this Aug 3, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgit-changed@​0.3.07610010086100

View full report

@pyramation
pyramation merged commit e853a90 into main Aug 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant