diff --git a/.changeset/empty-eggs-cross.md b/.changeset/empty-eggs-cross.md new file mode 100644 index 0000000000..b7d4cb1871 --- /dev/null +++ b/.changeset/empty-eggs-cross.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": minor +--- + +More information added to the Git check errors and prompt. diff --git a/packages/plugin-commands-publishing/src/publish.ts b/packages/plugin-commands-publishing/src/publish.ts index a85b81f6a8..a3af9bcfa9 100644 --- a/packages/plugin-commands-publishing/src/publish.ts +++ b/packages/plugin-commands-publishing/src/publish.ts @@ -83,6 +83,8 @@ export function help () { }) } +const GIT_CHECKS_HINT = 'If you want to disable Git checks on publish, set the "git-checks" setting to "false".' + export async function handler ( opts: Omit & { argv: { @@ -96,22 +98,30 @@ export async function handler ( ) { if (opts.gitChecks !== false && await isGitRepo()) { const branch = opts.publishBranch ?? 'master' - if (await getCurrentBranch() !== branch) { + const currentBranch = await getCurrentBranch() + if (currentBranch !== branch) { const { confirm } = await prompt({ - message: `You are not on ${branch} branch, do you want to continue?`, + message: `You're on branch "${currentBranch}" but your "publish-branch" is set to "${branch}". \ +Do you want to continue?`, name: 'confirm', type: 'confirm', } as any) as any // eslint-disable-line @typescript-eslint/no-explicit-any if (!confirm) { - throw new PnpmError('GIT_NOT_CORRECT_BRANCH', `Branch is not on '${branch}'.`) + throw new PnpmError('GIT_NOT_CORRECT_BRANCH', `Branch is not on '${branch}'.`, { + hint: GIT_CHECKS_HINT, + }) } } if (!(await isWorkingTreeClean())) { - throw new PnpmError('GIT_NOT_UNCLEAN', 'Unclean working tree. Commit or stash changes first.') + 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.') + throw new PnpmError('GIT_NOT_LATEST', 'Remote history differs. Please pull changes.', { + hint: GIT_CHECKS_HINT, + }) } } if (opts.recursive && opts.selectedProjectsGraph) {