feat(cli): Initialize a git repository and create an initial commit on scaffold#1484
feat(cli): Initialize a git repository and create an initial commit on scaffold#1484ryohidaka wants to merge 2 commits intovoidzero-dev:mainfrom
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
5daa636 to
d1fb08e
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37a56e2176
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await initGitRepository(workspaceInfo.rootDir); | ||
| await createInitialCommit(workspaceInfo.rootDir); |
There was a problem hiding this comment.
Limit initial commits to generated files
In an existing monorepo, opting into --git runs the commit from workspaceInfo.rootDir; createInitialCommit does git add -A, which stages every tracked/untracked change in that repo (confirmed via git add -h). If the user has unrelated dirty work anywhere in the monorepo, vp create ... --git will include it in the scaffold's "Initial commit" rather than only the new project/workspace edits.
Useful? React with 👍 / 👎.
| onCancel: () => cancelAndExit(), | ||
| })); | ||
|
|
||
| const shouldSetupGit = await promptGitInit(options); |
There was a problem hiding this comment.
Honor --no-git for monorepo scaffolds
promptGitInit(options) returns false for vp create vite:monorepo --no-git, but the monorepo-template path still uses its separate shouldInitGit default and calls git init later. In the default compact mode this happens without another prompt, so the newly documented --no-git option does not actually skip repository initialization for monorepo scaffolds.
Useful? React with 👍 / 👎.
| await initGitRepository(workspaceInfo.rootDir); | ||
| await createInitialCommit(workspaceInfo.rootDir); |
There was a problem hiding this comment.
Limit initial commits to generated files
In an existing monorepo, opting into --git runs the commit from workspaceInfo.rootDir; createInitialCommit does git add -A, which stages every tracked/untracked change in that repo. If the user has unrelated dirty work anywhere in the monorepo, vp create ... --git will include it in the scaffold's "Initial commit" rather than only the new project/workspace edits.
Useful? React with 👍 / 👎.
| if (shouldSetupGit) { | ||
| updateCreateProgress('Initializing git repository'); | ||
| await initGitRepository(fullPath); | ||
| } |
There was a problem hiding this comment.
Add node_modules to .gitignore before standalone commits
For standalone scaffolds, --git initializes the repository before installing dependencies but never calls ensureGitignoreNodeModules; the bundled vite:generator template has no .gitignore, and arbitrary bundled/remote templates can omit one too. In those cases the later git add -A initial commit runs after vp install, so it will commit the generated node_modules directory.
Useful? React with 👍 / 👎.
| if (shouldSetupGit) { | ||
| updateCreateProgress('Creating initial commit'); | ||
| await createInitialCommit(fullPath); |
There was a problem hiding this comment.
Surface failed initial commits
createInitialCommit returns whether git commit succeeded, but this result is ignored here, so a common failure such as missing user.name/user.email or a failing pre-commit hook leaves the scaffold without the promised initial commit while the command still prints the normal success summary. Check the return value and show the captured git error or fail the command when --git was requested.
Useful? React with 👍 / 👎.
| await runViteFmt(fullPath, options.interactive, undefined, { silent: compactOutput }); | ||
| if (shouldSetupGit) { | ||
| updateCreateProgress('Creating initial commit'); | ||
| await createInitialCommit(fullPath); |
There was a problem hiding this comment.
Skip committing when setup steps failed
The initial commit is created even when the preceding install or formatter step failed; runViteInstall records status: 'failed' and runViteFmt returns a failed summary, but neither result gates this block. When vp install or vp fmt --write fails for a generated template, --git still commits the broken or partially generated state as the initial commit, making the user unwind that commit before fixing the scaffold.
Useful? React with 👍 / 👎.
33df323 to
39a7bbc
Compare
39a7bbc to
9512eeb
Compare
Summary
Add a
--git/--no-gitflag tovp create.git initbefore installing dependencies,then
git add -A && git commit -m "Initial commit from Vite+"after formatting completesTesting
snap-tests-globalbootstrap-cliand confirm that it worksCloses #1483