mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-19 14:20:36 -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[]
|
params: string[]
|
||||||
) {
|
) {
|
||||||
if (opts.gitChecks !== false && await isGitRepo()) {
|
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 branch = opts.publishBranch ?? 'master'
|
||||||
const currentBranch = await getCurrentBranch()
|
const currentBranch = await getCurrentBranch()
|
||||||
if (currentBranch !== branch) {
|
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())) {
|
if (!(await isRemoteHistoryClean())) {
|
||||||
throw new PnpmError('GIT_NOT_LATEST', 'Remote history differs. Please pull changes.', {
|
throw new PnpmError('GIT_NOT_LATEST', 'Remote history differs. Please pull changes.', {
|
||||||
hint: GIT_CHECKS_HINT,
|
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', ['init'])
|
||||||
await execa('git', ['checkout', '-b', 'test'])
|
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({
|
prompt.returns({
|
||||||
confirm: false,
|
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', ['init'])
|
||||||
await execa('git', ['checkout', '-b', 'master'])
|
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({
|
prompt.returns({
|
||||||
confirm: false,
|
confirm: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user