fix(publish): check branch after checking if branch is clean

This commit is contained in:
Zoltan Kochan
2020-09-23 00:32:47 +03:00
parent cfd15f5d8b
commit 892e2b1551
3 changed files with 18 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-publishing": patch
---
The order of Git checks is changed. The branch is checked after the cleannes check.

View File

@@ -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,

View File

@@ -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,