Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prettier][eslint] Support sapling in prettier changed files command #30149

Merged
merged 1 commit into from
Jun 30, 2024
Merged
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
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;