mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-12 18:49:41 -04:00
fix(publish): check branch after checking if branch is clean
This commit is contained in:
5
.changeset/brave-coats-look.md
Normal file
5
.changeset/brave-coats-look.md
Normal 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.
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user