fix(core): properly diff json from the merge-base (#15476)

This commit is contained in:
Jason Jean 2023-03-06 13:54:20 -05:00 committed by GitHub
parent 7d25c69579
commit ffac350e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,6 +166,10 @@ export function splitArgsIntoNxArgsAndOverrides(
}); });
} }
} }
if (nxArgs.base) {
nxArgs.base = getMergeBase(nxArgs.base, nxArgs.head);
}
} }
if (!nxArgs.skipNxCache) { if (!nxArgs.skipNxCache) {
@ -231,25 +235,33 @@ function getUntrackedFiles(): string[] {
return parseGitOutput(`git ls-files --others --exclude-standard`); return parseGitOutput(`git ls-files --others --exclude-standard`);
} }
function getFilesUsingBaseAndHead(base: string, head: string): string[] { function getMergeBase(base: string, head: string = 'HEAD') {
let mergeBase: string;
try { try {
mergeBase = execSync(`git merge-base "${base}" "${head}"`, { return execSync(`git merge-base "${base}" "${head}"`, {
maxBuffer: TEN_MEGABYTES, maxBuffer: TEN_MEGABYTES,
cwd: workspaceRoot, cwd: workspaceRoot,
stdio: 'pipe',
}) })
.toString() .toString()
.trim(); .trim();
} catch { } catch {
mergeBase = execSync(`git merge-base --fork-point "${base}" "${head}"`, { try {
maxBuffer: TEN_MEGABYTES, return execSync(`git merge-base --fork-point "${base}" "${head}"`, {
cwd: workspaceRoot, maxBuffer: TEN_MEGABYTES,
}) cwd: workspaceRoot,
.toString() stdio: 'pipe',
.trim(); })
.toString()
.trim();
} catch {
return base;
}
} }
}
function getFilesUsingBaseAndHead(base: string, head: string): string[] {
return parseGitOutput( return parseGitOutput(
`git diff --name-only --no-renames --relative "${mergeBase}" "${head}"` `git diff --name-only --no-renames --relative "${base}" "${head}"`
); );
} }