Skip to content

Commit

Permalink
fix(release): support workspace root to be subdirectory of git root
Browse files Browse the repository at this point in the history
closed nrwl#27995
  • Loading branch information
shantanuveve authored and shantanu1227 committed Nov 5, 2024
1 parent b925f8c commit ca5accc
Showing 1 changed file with 23 additions and 4 deletions.
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';
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 = [
'--no-pager',
'log',
range,
`--pretty="----%n%s${separator}%h${separator}%an${separator}%ae%n%b"`,
'--name-status',
]);
];
const relativePath = await getWorkspaceRelativePath();
if (relativePath) {
args.push(`--relative=${relativePath}`);
}

// https://git-scm.com/docs/pretty-formats
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() {
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);
}

0 comments on commit ca5accc

Please sign in to comment.