diff --git a/.changeset/brave-coats-look.md b/.changeset/brave-coats-look.md new file mode 100644 index 0000000000..4dcf40b6c2 --- /dev/null +++ b/.changeset/brave-coats-look.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": patch +--- + +The order of Git checks is changed. The branch is checked after the cleannes check. diff --git a/packages/plugin-commands-publishing/src/publish.ts b/packages/plugin-commands-publishing/src/publish.ts index a3af9bcfa9..8afeed387a 100644 --- a/packages/plugin-commands-publishing/src/publish.ts +++ b/packages/plugin-commands-publishing/src/publish.ts @@ -97,6 +97,11 @@ export async function handler ( params: string[] ) { if (opts.gitChecks !== false && await isGitRepo()) { + if (!(await isWorkingTreeClean())) { + throw new PnpmError('GIT_NOT_UNCLEAN', 'Unclean working tree. Commit or stash changes first.', { + hint: GIT_CHECKS_HINT, + }) + } const branch = opts.publishBranch ?? 'master' const currentBranch = await getCurrentBranch() if (currentBranch !== branch) { @@ -113,11 +118,6 @@ Do you want to continue?`, }) } } - if (!(await isWorkingTreeClean())) { - throw new PnpmError('GIT_NOT_UNCLEAN', 'Unclean working tree. Commit or stash changes first.', { - hint: GIT_CHECKS_HINT, - }) - } if (!(await isRemoteHistoryClean())) { throw new PnpmError('GIT_NOT_LATEST', 'Remote history differs. Please pull changes.', { hint: GIT_CHECKS_HINT, diff --git a/packages/plugin-commands-publishing/test/gitChecks.ts b/packages/plugin-commands-publishing/test/gitChecks.ts index 4bb7e8ccdb..094b411f19 100644 --- a/packages/plugin-commands-publishing/test/gitChecks.ts +++ b/packages/plugin-commands-publishing/test/gitChecks.ts @@ -30,6 +30,10 @@ test('publish: fails git check if branch is not on master', async (t) => { await execa('git', ['init']) await execa('git', ['checkout', '-b', 'test']) + await execa('git', ['config', 'user.email', 'x@y.z']) + await execa('git', ['config', 'user.name', 'xyz']) + await execa('git', ['add', '*']) + await execa('git', ['commit', '-m', 'init', '--no-gpg-sign']) prompt.returns({ confirm: false, @@ -60,6 +64,10 @@ test('publish: fails git check if branch is not on specified branch', async (t) await execa('git', ['init']) await execa('git', ['checkout', '-b', 'master']) + await execa('git', ['config', 'user.email', 'x@y.z']) + await execa('git', ['config', 'user.name', 'xyz']) + await execa('git', ['add', '*']) + await execa('git', ['commit', '-m', 'init', '--no-gpg-sign']) prompt.returns({ confirm: false,