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

fix(release): support workspace root as a subdirectory of git root #28650

Merged
Merged
Changes from 1 commit
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
27 changes: 23 additions & 4 deletions packages/nx/src/command-line/release/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Special thanks to changelogen for the original inspiration for many of these utilities:
* https://github.com/unjs/changelogen
*/
import { relative } from 'path';
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved
import { interpolate } from '../../../tasks-runner/utils';
import { workspaceRoot } from '../../../utils/workspace-root';
import { execCommand } from './exec-command';
Expand Down Expand Up @@ -124,15 +125,20 @@ export async function getGitDiff(

// Use a unique enough separator that we can be relatively certain will not occur within the commit message itself
const separator = '§§§';

// https://git-scm.com/docs/pretty-formats
const r = await execCommand('git', [
const args = [
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved
'--no-pager',
'log',
range,
`--pretty="----%n%s${separator}%h${separator}%an${separator}%ae%n%b"`,
'--name-status',
]);
];
const relativePath = await getWorkspaceRelativePath();
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved
if (relativePath) {
args.push(`--relative=${relativePath}`);
}

// https://git-scm.com/docs/pretty-formats
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved
const r = await execCommand('git', args);

return r
.split('----\n')
Expand Down Expand Up @@ -558,3 +564,16 @@ export async function getFirstGitCommit() {
throw new Error(`Unable to find first commit in git history`);
}
}

export async function getGitRoot() {
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved
try {
return (await execCommand('git', ['rev-parse', '--show-toplevel'])).trim();
} catch (e) {
throw new Error('Unable to find git root');
}
}

async function getWorkspaceRelativePath() {
const gitRoot = await getGitRoot();
return relative(gitRoot, workspaceRoot);
}
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved