@@ -387,25 +387,6 @@ export async function createProject(opts: CreateOptions) {
387387 'node_modules\ndist\n.env\n' ,
388388 'utf8' ,
389389 ) ;
390- if ( ! ( toolOptions . noCommit ?? false ) ) {
391- try {
392- runCommand (
393- 'git' ,
394- [ 'add' , '-A' ] ,
395- target ,
396- toolOptions . verbose ?? false ,
397- ) ;
398- runCommand (
399- 'git' ,
400- [ 'commit' , '-m' , 'chore: initial commit' ] ,
401- target ,
402- toolOptions . verbose ?? false ,
403- ) ;
404- } catch ( e ) {
405- const errMsg = e instanceof Error ? e . message : String ( e ) ;
406- console . warn ( MESSAGES . gitCommitFailed ( errMsg ) ) ;
407- }
408- }
409390 }
410391 }
411392 } catch ( e ) {
@@ -447,4 +428,56 @@ export async function createProject(opts: CreateOptions) {
447428 console . warn ( MESSAGES . installFailed ( pm , errMsg ) ) ;
448429 }
449430 }
431+
432+ // Git initial commit AFTER npm install to include package-lock.json
433+ if ( ( toolOptions . git ?? true ) && ! ( toolOptions . noCommit ?? false ) ) {
434+ try {
435+ const gitAvailable = runCommand (
436+ 'git' ,
437+ [ '--version' ] ,
438+ target ,
439+ false ,
440+ true ,
441+ ) ;
442+ if ( gitAvailable ) {
443+ const insideRepo = runCommand (
444+ 'git' ,
445+ [ 'rev-parse' , '--is-inside-work-tree' ] ,
446+ target ,
447+ false ,
448+ true ,
449+ ) ;
450+ const hasCommits = runCommand (
451+ 'git' ,
452+ [ 'rev-parse' , 'HEAD' ] ,
453+ target ,
454+ false ,
455+ true ,
456+ ) ;
457+
458+ if ( ! insideRepo || ! hasCommits ) {
459+ try {
460+ runCommand (
461+ 'git' ,
462+ [ 'add' , '-A' ] ,
463+ target ,
464+ toolOptions . verbose ?? false ,
465+ ) ;
466+ runCommand (
467+ 'git' ,
468+ [ 'commit' , '-m' , 'chore: initial commit' ] ,
469+ target ,
470+ toolOptions . verbose ?? false ,
471+ ) ;
472+ } catch ( e ) {
473+ const errMsg = e instanceof Error ? e . message : String ( e ) ;
474+ console . warn ( MESSAGES . gitCommitFailed ( errMsg ) ) ;
475+ }
476+ }
477+ }
478+ } catch ( e ) {
479+ const errMsg = e instanceof Error ? e . message : String ( e ) ;
480+ console . warn ( MESSAGES . gitCommitFailed ( errMsg ) ) ;
481+ }
482+ }
450483}
0 commit comments