@@ -29,13 +29,15 @@ import {
2929 writeAgentInstructions ,
3030} from '../utils/agent.ts' ;
3131import { detectExistingEditors , selectEditors , writeEditorConfigs } from '../utils/editor.ts' ;
32+ import { createInitialCommit , initGitRepository } from '../utils/git.ts' ;
3233import { renderCliDoc } from '../utils/help.ts' ;
3334import { displayRelative } from '../utils/path.ts' ;
3435import {
3536 type CommandRunSummary ,
3637 defaultInteractive ,
3738 downloadPackageManager ,
3839 promptGitHooks ,
40+ promptGitInit ,
3941 runViteFmt ,
4042 runViteInstall ,
4143 selectPackageManager ,
@@ -106,6 +108,8 @@ const helpMessage = renderCliDoc({
106108 label : '--editor NAME' ,
107109 description : 'Write editor config files for the specified editor.' ,
108110 } ,
111+ { label : '--git' , description : 'Initialize a git repository with an initial commit' } ,
112+ { label : '--no-git' , description : 'Skip git repository initialization' } ,
109113 {
110114 label : '--hooks' ,
111115 description : 'Set up pre-commit hooks (default in non-interactive mode)' ,
@@ -235,11 +239,12 @@ function parseArgs() {
235239 verbose ?: boolean ;
236240 agent ?: string | string [ ] | false ;
237241 editor ?: string ;
242+ git ?: boolean ;
238243 hooks ?: boolean ;
239244 'package-manager' ?: string ;
240245 } > ( viteArgs , {
241246 alias : { h : 'help' } ,
242- boolean : [ 'help' , 'list' , 'all' , 'interactive' , 'hooks' , 'verbose' ] ,
247+ boolean : [ 'help' , 'list' , 'all' , 'interactive' , 'hooks' , 'verbose' , 'git' ] ,
243248 string : [ 'directory' , 'agent' , 'editor' , 'package-manager' ] ,
244249 default : { interactive : defaultInteractive ( ) } ,
245250 } ) ;
@@ -256,6 +261,7 @@ function parseArgs() {
256261 verbose : parsed . verbose || false ,
257262 agent : parsed . agent ,
258263 editor : parsed . editor ,
264+ git : parsed . git ,
259265 hooks : parsed . hooks ,
260266 packageManager : parsed [ 'package-manager' ] ,
261267 } as Options ,
@@ -747,6 +753,7 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
747753 onCancel : ( ) => cancelAndExit ( ) ,
748754 } ) ) ;
749755
756+ const shouldSetupGit = await promptGitInit ( options ) ;
750757 if ( ! isMonorepo ) {
751758 shouldSetupHooks = await promptGitHooks ( options ) ;
752759 }
@@ -827,7 +834,7 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
827834 // #region Handle monorepo template
828835 if ( templateInfo . command === BuiltinTemplate . monorepo || isBundledMonorepo ) {
829836 // Ask up-front so the prompt isn't buried under scaffold output.
830- let shouldInitGit = true ;
837+ let shouldInitGit = shouldSetupGit ;
831838 if ( options . interactive && ! compactOutput ) {
832839 pauseCreateProgress ( ) ;
833840 const selected = await prompts . confirm ( {
@@ -841,7 +848,7 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
841848 } else {
842849 shouldInitGit = selected ;
843850 }
844- } else if ( ! compactOutput ) {
851+ } else if ( shouldInitGit && ! compactOutput ) {
845852 prompts . log . info ( 'Initializing git repository (default: yes)' ) ;
846853 }
847854
@@ -902,6 +909,10 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
902909 workspaceInfo . rootDir = fullPath ;
903910 updateCreateProgress ( 'Integrating monorepo' ) ;
904911 rewriteMonorepo ( workspaceInfo , undefined , compactOutput ) ;
912+ if ( shouldSetupGit ) {
913+ updateCreateProgress ( 'Initializing git repository' ) ;
914+ await initGitRepository ( fullPath ) ;
915+ }
905916 if ( bundled ?. monorepo ) {
906917 // Wire `create.defaultTemplate: '<scope>'` into the new workspace's
907918 // vite.config.ts so a bare `vp create` from inside it opens the
@@ -922,6 +933,13 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
922933 } ) ;
923934 updateCreateProgress ( 'Formatting code' ) ;
924935 await runViteFmt ( fullPath , options . interactive , undefined , { silent : compactOutput } ) ;
936+ if ( shouldSetupGit ) {
937+ updateCreateProgress ( 'Creating initial commit' ) ;
938+ const committed = await createInitialCommit ( fullPath ) ;
939+ if ( ! committed ) {
940+ prompts . log . warn ( 'Initial commit failed. Check your git user.name/user.email config' ) ;
941+ }
942+ }
925943 clearCreateProgress ( ) ;
926944 showCreateSummary ( {
927945 description : describeScaffold ( selectedTemplateName , selectedTemplateArgs ) ,
@@ -1137,6 +1155,11 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
11371155 await runViteFmt ( workspaceInfo . rootDir , options . interactive , [ projectDir ] , {
11381156 silent : compactOutput ,
11391157 } ) ;
1158+ if ( shouldSetupGit ) {
1159+ updateCreateProgress ( 'Creating initial commit' ) ;
1160+ await initGitRepository ( workspaceInfo . rootDir ) ;
1161+ await createInitialCommit ( workspaceInfo . rootDir ) ;
1162+ }
11401163 } else {
11411164 if ( shouldMigrateLintFmtTools ) {
11421165 await installAndMigrate ( fullPath ) ;
@@ -1148,6 +1171,10 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
11481171 addFrameworkShim ( fullPath , framework ) ;
11491172 }
11501173 }
1174+ if ( shouldSetupGit ) {
1175+ updateCreateProgress ( 'Initializing git repository' ) ;
1176+ await initGitRepository ( fullPath ) ;
1177+ }
11511178 if ( shouldSetupHooks ) {
11521179 installGitHooks ( fullPath , compactOutput ) ;
11531180 }
@@ -1159,6 +1186,13 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
11591186 } ) ;
11601187 updateCreateProgress ( 'Formatting code' ) ;
11611188 await runViteFmt ( fullPath , options . interactive , undefined , { silent : compactOutput } ) ;
1189+ if ( shouldSetupGit ) {
1190+ updateCreateProgress ( 'Creating initial commit' ) ;
1191+ const committed = await createInitialCommit ( fullPath ) ;
1192+ if ( ! committed ) {
1193+ prompts . log . warn ( 'Initial commit failed. Check your git user.name/user.email config' ) ;
1194+ }
1195+ }
11621196 }
11631197
11641198 clearCreateProgress ( ) ;
0 commit comments