Sitelet https://github.com/redis/node-redis/pull/3265/files
Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
fetch-depth: 0
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
Expand Down
26 changes: 14 additions & 12 deletions scripts/lint-changed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { fileURLToPath } from 'node:url';
/**
* Incremental lint gate for this monorepo.
*
* CI runs this on pull requests and lints only files changed against the PR's
* base commit, so we can enforce linting on new work without fixing the whole
* repository at once. Local runs lint staged, unstaged, and untracked files.
* CI runs this on pull requests and lints only files changed by the PR, so we
* can enforce linting on new work without fixing the whole repository at once.
* Local runs lint staged, unstaged, and untracked files.
*
* Use `--base <sha-or-ref> [--head <sha-or-ref>]` to reproduce a CI-style diff.
* Use `--base <sha-or-ref> [--head <sha-or-ref>]` to reproduce a CI-style
* merge-base diff.
*/
const lintableFilePattern = /\.(?:cjs|js|mjs|ts)$/u;
const ignoredPathPattern = /(^|\/)(coverage|dist|documentation|junit-results|node_modules)\//u;
Expand Down Expand Up @@ -86,15 +87,14 @@ function uniqueLines(output) {
}

function changedFilesBetween(base, head) {
// actions/checkout uses a shallow checkout, so the PR base commit often is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shallow fetch incompatible with three-dot merge-base diff

Low Severity

The ensureCommitAvailable fallback fetch uses --depth=1, which only retrieves the commit object itself. The new three-dot diff syntax (${base}...${head}) requires git to compute the merge-base by traversing commit history from both refs to a common ancestor. If ensureCommitAvailable actually needs to fetch (i.e., a commit isn't already present), the --depth=1 fetch won't provide enough history for git merge-base to succeed, causing the git diff call to fail. CI is unaffected due to fetch-depth: 0, but the --base flag path for local reproduction is broken in this scenario.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e6fbc01. Configure here.

// not present locally even though GitHub exposes the SHA in the event JSON.
ensureCommitAvailable(base);
ensureCommitAvailable(head);

return uniqueLines(git([
'diff',
'--name-only',
'--diff-filter=ACMR',
base,
head
`${base}...${head}`
]));
}

Expand All @@ -112,13 +112,15 @@ function getCandidateFiles(options) {
}

if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
const baseSha = getGitHubEvent().pull_request?.base?.sha;
const pullRequest = getGitHubEvent().pull_request;
const baseSha = pullRequest?.base?.sha;
const headSha = pullRequest?.head?.sha;

if (!baseSha) {
throw new Error('Unable to determine pull request base SHA');
if (!baseSha || !headSha) {
throw new Error('Unable to determine pull request base and head SHAs');
}

return changedFilesBetween(baseSha, options.head);
return changedFilesBetween(baseSha, headSha);
}

return changedFilesInWorkingTree();
Expand Down
Loading