@@ -22,13 +22,16 @@ const isRootGitRepo = (dir: string): boolean => {
22
22
} ;
23
23
24
24
/** If dir is inside a git worktree, meaning a parent directory has `.git` */
25
- const isInsideGitRepo = ( dir : string ) : boolean => {
25
+ const isInsideGitRepo = async ( dir : string ) : Promise < boolean > => {
26
26
try {
27
- const stdout = execSync ( "git rev-parse --is-inside-work-tree" , {
27
+ // If this command succeeds, we're inside a git repo
28
+ await execa ( "git" , [ "rev-parse" , "--is-inside-work-tree" ] , {
28
29
cwd : dir ,
29
- } ) . toString ( ) ;
30
- return stdout . trim ( ) === "true" ;
30
+ stdout : "ignore" ,
31
+ } ) ;
32
+ return true ;
31
33
} catch ( _e ) {
34
+ // Else, it will throw a git-error and we return false
32
35
return false ;
33
36
}
34
37
} ;
@@ -53,12 +56,12 @@ export const initializeGit = async (projectDir: string) => {
53
56
const spinner = ora ( "Creating a new git repo...\n" ) . start ( ) ;
54
57
55
58
const isRoot = isRootGitRepo ( projectDir ) ;
56
- const isInside = isInsideGitRepo ( projectDir ) ;
59
+ const isInside = await isInsideGitRepo ( projectDir ) ;
57
60
const dirName = path . parse ( projectDir ) . name ; // skip full path for logging
58
61
59
62
if ( isInside && isRoot ) {
60
63
// Dir is a root git repo
61
- spinner . stopAndPersist ( ) ;
64
+ spinner . stop ( ) ;
62
65
const { overwriteGit } = await inquirer . prompt < {
63
66
overwriteGit : boolean ;
64
67
} > ( {
@@ -77,7 +80,7 @@ export const initializeGit = async (projectDir: string) => {
77
80
fs . removeSync ( path . join ( projectDir , ".git" ) ) ;
78
81
} else if ( isInside && ! isRoot ) {
79
82
// Dir is inside a git worktree
80
- spinner . stopAndPersist ( ) ;
83
+ spinner . stop ( ) ;
81
84
const { initializeChildGitRepo } = await inquirer . prompt < {
82
85
initializeChildGitRepo : boolean ;
83
86
} > ( {
0 commit comments