Skip to content

Commit

Permalink
[prettier][eslint] Support sapling in prettier changed files command
Browse files Browse the repository at this point in the history
Summary: The listChangesFiles module didn't work under sapling; this fixes

ghstack-source-id: 9f685de5e7550075369723b845104ac0e676ce95
Pull Request resolved: #30149
  • Loading branch information
mvitousek committed Jun 30, 2024
1 parent 2e72ea8 commit 05cebff
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions scripts/shared/listChangedFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,46 @@ const exec = (command, args) => {
return execFileSync(command, args, options);
};

const isGit = () => {
try {
const wt = execGitCmd(['rev-parse', '--is-inside-work-tree']);
return wt.length > 0 && wt[0] === 'true';
} catch (_e) {
return false;
}
};

const isSl = () => {
try {
execSlCmd(['whereami']);
return true;
} catch (_e) {
return false;
}
};

const execGitCmd = args => exec('git', args).trim().toString().split('\n');
const execSlCmd = args => exec('sl', args).trim().toString().split('\n');

const listChangedFiles = () => {
const mergeBase = execGitCmd(['merge-base', 'HEAD', 'main']);
return new Set([
...execGitCmd(['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase]),
...execGitCmd(['ls-files', '--others', '--exclude-standard']),
]);
if (isGit()) {
const mergeBase = execGitCmd(['merge-base', 'HEAD', 'main']);
return new Set([
...execGitCmd([
'diff',
'--name-only',
'--diff-filter=ACMRTUB',
mergeBase,
]),
...execGitCmd(['ls-files', '--others', '--exclude-standard']),
]);
} else if (isSl()) {
const mergeBase = execSlCmd(['log', '-r', 'last(public() & ::.)'])[0]
.trim()
.split(/\s+/)[1];
return new Set(execSlCmd(['status', '--no-status', '--rev', mergeBase]));
}
throw new Error('Not a git or sl repo');
};

module.exports = listChangedFiles;

0 comments on commit 05cebff

Please sign in to comment.