From 48a664e38add7dd3bab6d5e2ca0ff2ec2d6ae14e Mon Sep 17 00:00:00 2001 From: MK Date: Thu, 11 Jun 2026 23:29:02 +0800 Subject: [PATCH 1/2] fix(cli): surface git output when initial commit fails The warning always suggested checking git user.name/user.email even when the commit failed for other reasons (e.g. a failing pre-commit hook). Show the actual git commit output instead, and add a snap test covering the failure path. --- .../hooks/pre-commit | 3 +++ .../mock-manifest.json | 24 ++++++++++++++++++ .../create-org-bundled-commit-fail/snap.txt | 11 ++++++++ .../create-org-bundled-commit-fail/steps.json | 11 ++++++++ .../tarballs/create-1.0.0.tgz | Bin 0 -> 436 bytes packages/cli/src/create/bin.ts | 18 ++++++++----- packages/cli/src/utils/git.ts | 13 ++++++++-- 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100755 packages/cli/snap-tests/create-org-bundled-commit-fail/hooks/pre-commit create mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json create mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt create mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json create mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/tarballs/create-1.0.0.tgz diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/hooks/pre-commit b/packages/cli/snap-tests/create-org-bundled-commit-fail/hooks/pre-commit new file mode 100755 index 0000000000..689ea9b9c2 --- /dev/null +++ b/packages/cli/snap-tests/create-org-bundled-commit-fail/hooks/pre-commit @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Mock pre-commit hook rejecting the initial commit" >&2 +exit 1 diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json b/packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json new file mode 100644 index 0000000000..8f04735408 --- /dev/null +++ b/packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json @@ -0,0 +1,24 @@ +{ + "@your-org/create": { + "name": "@your-org/create", + "dist-tags": { "latest": "1.0.0" }, + "versions": { + "1.0.0": { + "version": "1.0.0", + "dist": { + "tarball": "{REGISTRY}/@your-org/create/-/create-1.0.0.tgz", + "integrity": "sha512-swwZCXG8RDBJNTmiw3zCOBCQx9bCg7wHqoW37aV7BgGYfBUU7n7c+efbSCg0+FpdLhgeUjEMP5IAO+8exmeFKg==" + }, + "createConfig": { + "templates": [ + { + "name": "demo", + "description": "Bundled demo template", + "template": "./templates/demo" + } + ] + } + } + } + } +} diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt b/packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt new file mode 100644 index 0000000000..fcd5b96417 --- /dev/null +++ b/packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt @@ -0,0 +1,11 @@ +> node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org:demo --no-interactive --directory my-demo-app --git # failing pre-commit hook (via core.hooksPath) aborts the initial commit; git output is surfaced + +Initial commit failed + +Mock pre-commit hook rejecting the initial commit +◇ Scaffolded my-demo-app +• Node pnpm +→ Next: cd my-demo-app && vp run + +> test -d my-demo-app/.git && echo 'Git initialized' # repository still created despite failed commit +Git initialized diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json b/packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json new file mode 100644 index 0000000000..9ad667f7f6 --- /dev/null +++ b/packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json @@ -0,0 +1,11 @@ +{ + "env": { + "GIT_CONFIG_COUNT": "1", + "GIT_CONFIG_KEY_0": "core.hooksPath", + "GIT_CONFIG_VALUE_0": "../hooks" + }, + "commands": [ + "node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org:demo --no-interactive --directory my-demo-app --git # failing pre-commit hook (via core.hooksPath) aborts the initial commit; git output is surfaced", + "test -d my-demo-app/.git && echo 'Git initialized' # repository still created despite failed commit" + ] +} diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/tarballs/create-1.0.0.tgz b/packages/cli/snap-tests/create-org-bundled-commit-fail/tarballs/create-1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..b73b8ed8cd21806e348f9caa5995bdc798178622 GIT binary patch literal 436 zcmV;l0ZaZLiwFP!000006YZ8wYlA=#Ky&t24EEaUZlVdK6q+VN4+$x`l~Tm&HrPg2 zb~hoVg+`BbD?zK|T!tGYt}Ew!ysp;8StM#n=u73luXi zb#}&tjCraHs6{MNtVT?RBFHW^jIqo<(M2C4b%HkpHCN?D|h#^uH3=JmW$^$Wy66&jGk8|GU?y z?isMh|B=_}4LmD}j?v?w|E|03f1}x;=zk?#KyUN(Y#1F#;xtZz3A~iY>t)Wufq) { return result.exitCode === 0; } -export async function createInitialCommit(cwd: string): Promise { +export interface InitialCommitResult { + success: boolean; + /** Combined stdout/stderr from `git commit`, for diagnosing failures (e.g. a failing pre-commit hook). */ + output: string; +} + +export async function createInitialCommit(cwd: string): Promise { await runCommandSilently({ command: 'git', args: ['add', '-A'], @@ -23,5 +29,8 @@ export async function createInitialCommit(cwd: string): Promise { cwd, envs: process.env, }); - return result.exitCode === 0; + return { + success: result.exitCode === 0, + output: `${result.stdout.toString()}${result.stderr.toString()}`.trim(), + }; } From b83cfd2828c039a907203d25b239478c2640fa1f Mon Sep 17 00:00:00 2001 From: MK Date: Thu, 11 Jun 2026 23:37:26 +0800 Subject: [PATCH 2/2] test(cli): use builtin vite:monorepo template in commit-fail snap test The bundled org fixture (mock registry, manifest, tarball) is not needed to exercise the initial-commit failure path. The builtin template runs fully offline and shrinks the fixture to steps.json plus the hook. --- .../hooks/pre-commit | 0 .../create-git-commit-fail/snap.txt | 11 ++++++++ .../create-git-commit-fail/steps.json | 11 ++++++++ .../mock-manifest.json | 24 ------------------ .../create-org-bundled-commit-fail/snap.txt | 11 -------- .../create-org-bundled-commit-fail/steps.json | 11 -------- .../tarballs/create-1.0.0.tgz | Bin 436 -> 0 bytes 7 files changed, 22 insertions(+), 46 deletions(-) rename packages/cli/snap-tests/{create-org-bundled-commit-fail => create-git-commit-fail}/hooks/pre-commit (100%) create mode 100644 packages/cli/snap-tests/create-git-commit-fail/snap.txt create mode 100644 packages/cli/snap-tests/create-git-commit-fail/steps.json delete mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json delete mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt delete mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json delete mode 100644 packages/cli/snap-tests/create-org-bundled-commit-fail/tarballs/create-1.0.0.tgz diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/hooks/pre-commit b/packages/cli/snap-tests/create-git-commit-fail/hooks/pre-commit similarity index 100% rename from packages/cli/snap-tests/create-org-bundled-commit-fail/hooks/pre-commit rename to packages/cli/snap-tests/create-git-commit-fail/hooks/pre-commit diff --git a/packages/cli/snap-tests/create-git-commit-fail/snap.txt b/packages/cli/snap-tests/create-git-commit-fail/snap.txt new file mode 100644 index 0000000000..00643f5e22 --- /dev/null +++ b/packages/cli/snap-tests/create-git-commit-fail/snap.txt @@ -0,0 +1,11 @@ +> vp create vite:monorepo --no-interactive --directory my-mono --git # failing pre-commit hook (via core.hooksPath) aborts the initial commit; git output is surfaced + +Initial commit failed + +Mock pre-commit hook rejecting the initial commit +◇ Scaffolded my-mono with Vite+ monorepo +• Node pnpm +→ Next: cd my-mono && vp run + +> test -d my-mono/.git && echo 'Git initialized' # repository still created despite failed commit +Git initialized diff --git a/packages/cli/snap-tests/create-git-commit-fail/steps.json b/packages/cli/snap-tests/create-git-commit-fail/steps.json new file mode 100644 index 0000000000..de3d517992 --- /dev/null +++ b/packages/cli/snap-tests/create-git-commit-fail/steps.json @@ -0,0 +1,11 @@ +{ + "env": { + "GIT_CONFIG_COUNT": "1", + "GIT_CONFIG_KEY_0": "core.hooksPath", + "GIT_CONFIG_VALUE_0": "../hooks" + }, + "commands": [ + "vp create vite:monorepo --no-interactive --directory my-mono --git # failing pre-commit hook (via core.hooksPath) aborts the initial commit; git output is surfaced", + "test -d my-mono/.git && echo 'Git initialized' # repository still created despite failed commit" + ] +} diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json b/packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json deleted file mode 100644 index 8f04735408..0000000000 --- a/packages/cli/snap-tests/create-org-bundled-commit-fail/mock-manifest.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "@your-org/create": { - "name": "@your-org/create", - "dist-tags": { "latest": "1.0.0" }, - "versions": { - "1.0.0": { - "version": "1.0.0", - "dist": { - "tarball": "{REGISTRY}/@your-org/create/-/create-1.0.0.tgz", - "integrity": "sha512-swwZCXG8RDBJNTmiw3zCOBCQx9bCg7wHqoW37aV7BgGYfBUU7n7c+efbSCg0+FpdLhgeUjEMP5IAO+8exmeFKg==" - }, - "createConfig": { - "templates": [ - { - "name": "demo", - "description": "Bundled demo template", - "template": "./templates/demo" - } - ] - } - } - } - } -} diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt b/packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt deleted file mode 100644 index fcd5b96417..0000000000 --- a/packages/cli/snap-tests/create-org-bundled-commit-fail/snap.txt +++ /dev/null @@ -1,11 +0,0 @@ -> node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org:demo --no-interactive --directory my-demo-app --git # failing pre-commit hook (via core.hooksPath) aborts the initial commit; git output is surfaced - -Initial commit failed - -Mock pre-commit hook rejecting the initial commit -◇ Scaffolded my-demo-app -• Node pnpm -→ Next: cd my-demo-app && vp run - -> test -d my-demo-app/.git && echo 'Git initialized' # repository still created despite failed commit -Git initialized diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json b/packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json deleted file mode 100644 index 9ad667f7f6..0000000000 --- a/packages/cli/snap-tests/create-org-bundled-commit-fail/steps.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "env": { - "GIT_CONFIG_COUNT": "1", - "GIT_CONFIG_KEY_0": "core.hooksPath", - "GIT_CONFIG_VALUE_0": "../hooks" - }, - "commands": [ - "node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org:demo --no-interactive --directory my-demo-app --git # failing pre-commit hook (via core.hooksPath) aborts the initial commit; git output is surfaced", - "test -d my-demo-app/.git && echo 'Git initialized' # repository still created despite failed commit" - ] -} diff --git a/packages/cli/snap-tests/create-org-bundled-commit-fail/tarballs/create-1.0.0.tgz b/packages/cli/snap-tests/create-org-bundled-commit-fail/tarballs/create-1.0.0.tgz deleted file mode 100644 index b73b8ed8cd21806e348f9caa5995bdc798178622..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 436 zcmV;l0ZaZLiwFP!000006YZ8wYlA=#Ky&t24EEaUZlVdK6q+VN4+$x`l~Tm&HrPg2 zb~hoVg+`BbD?zK|T!tGYt}Ew!ysp;8StM#n=u73luXi zb#}&tjCraHs6{MNtVT?RBFHW^jIqo<(M2C4b%HkpHCN?D|h#^uH3=JmW$^$Wy66&jGk8|GU?y z?isMh|B=_}4LmD}j?v?w|E|03f1}x;=zk?#KyUN(Y#1F#;xtZz3A~iY>t)Wufq)