Skip to content

Commit 5e7f42d

Browse files
committed
[prettier][eslint] Support sapling in prettier changed files command
Summary: The listChangesFiles module didn't work under sapling; this fixes [ghstack-poisoned]
1 parent 2e72ea8 commit 5e7f42d

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

scripts/shared/listChangedFiles.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,46 @@ const exec = (command, args) => {
1919
return execFileSync(command, args, options);
2020
};
2121

22+
const isGit = () => {
23+
try {
24+
const wt = execGitCmd(['rev-parse', '--is-inside-work-tree']);
25+
return wt.length > 0 && wt[0] === 'true';
26+
} catch (_e) {
27+
return false;
28+
}
29+
};
30+
31+
const isSl = () => {
32+
try {
33+
execSlCmd(['whereami']);
34+
return true;
35+
} catch (_e) {
36+
return false;
37+
}
38+
};
39+
2240
const execGitCmd = args => exec('git', args).trim().toString().split('\n');
41+
const execSlCmd = args => exec('sl', args).trim().toString().split('\n');
2342

2443
const listChangedFiles = () => {
25-
const mergeBase = execGitCmd(['merge-base', 'HEAD', 'main']);
26-
return new Set([
27-
...execGitCmd(['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase]),
28-
...execGitCmd(['ls-files', '--others', '--exclude-standard']),
29-
]);
44+
if (isGit()) {
45+
const mergeBase = execGitCmd(['merge-base', 'HEAD', 'main']);
46+
return new Set([
47+
...execGitCmd([
48+
'diff',
49+
'--name-only',
50+
'--diff-filter=ACMRTUB',
51+
mergeBase,
52+
]),
53+
...execGitCmd(['ls-files', '--others', '--exclude-standard']),
54+
]);
55+
} else if (isSl()) {
56+
const mergeBase = execSlCmd(['log', '-r', 'last(public() & ::.)'])[0]
57+
.trim()
58+
.split(/\s+/)[1];
59+
return new Set(execSlCmd(['status', '--no-status', '--rev', mergeBase]));
60+
}
61+
throw new Error('Not a git or sl repo');
3062
};
3163

3264
module.exports = listChangedFiles;

0 commit comments

Comments
 (0)