[prettier][eslint] Support sapling in prettier changed files command
Summary: The listChangesFiles module didn't work under sapling; this fixes ghstack-source-id: 9f685de5e7550075369723b845104ac0e676ce95 Pull Request resolved: https://github.com/facebook/react/pull/30149
Mike Vitousek committed
Jun 30, 2024 at 14:22 UTC
05cebffe16494367f38396a40a56db5866de96ab
1 file changed
+37
-5
scripts/shared/listChangedFiles.js
+37
-5
@@ -19,14 +19,46 @@ const exec = (command, args) => {
19
return execFileSync(command, args, options);
20
};
21
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
+
40
const execGitCmd = args => exec('git', args).trim().toString().split('\n');
41
+const execSlCmd = args => exec('sl', args).trim().toString().split('\n');
42
43
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');
62
};
63
64
module.exports = listChangedFiles;