Skip to content

Commit 8b2b10a

Browse files
committed
Parse renamed/quoted paths in pre-ci changed-file detection; use two-dot diff
1 parent a5a734f commit 8b2b10a

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

bin/pre-ci.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,29 @@ import {PRE_CI_GATES, CI_ONLY_GATES} from './ci-gates.js'
1313

1414
const affected = process.argv.includes('--affected')
1515

16+
// git may wrap paths with special chars in quotes; strip them.
17+
function unquote(path) {
18+
return path.replace(/^"(.*)"$/, '$1')
19+
}
20+
1621
// Changed files vs the merge-base with origin/main, plus the working tree.
1722
// Returns null if detection fails, so callers can fail safe (assume relevant).
1823
function changedFiles() {
1924
try {
2025
const base = execSync('git merge-base HEAD origin/main', {encoding: 'utf8'}).trim()
21-
const committed = execSync(`git diff --name-only ${base}...HEAD`, {encoding: 'utf8'})
26+
const committed = execSync(`git diff --name-only ${base}..HEAD`, {encoding: 'utf8'})
2227
const working = execSync('git status --porcelain', {encoding: 'utf8'})
2328
const files = new Set()
24-
for (const line of committed.split('\n')) if (line.trim()) files.add(line.trim())
25-
for (const line of working.split('\n')) if (line.slice(3).trim()) files.add(line.slice(3).trim())
29+
for (const line of committed.split('\n')) {
30+
const path = unquote(line.trim())
31+
if (path) files.add(path)
32+
}
33+
for (const line of working.split('\n')) {
34+
if (!line.trim()) continue
35+
let entry = line.slice(3).trim()
36+
if (entry.includes(' -> ')) entry = entry.split(' -> ').pop() // rename: keep the new path
37+
files.add(unquote(entry))
38+
}
2639
return [...files]
2740
} catch {
2841
return null

0 commit comments

Comments
 (0)