11import { existsSync , readFileSync } from 'node:fs' ;
2+ import { mkdir , rm } from 'node:fs/promises' ;
23
34import { KEY_VALUE_STORE_KEYS } from '@apify/consts' ;
45
@@ -9,12 +10,13 @@ import { useConsoleSpy } from '../../__setup__/hooks/useConsoleSpy.js';
910import { useTempPath } from '../../__setup__/hooks/useTempPath.js' ;
1011
1112const actName = 'create-my-actor' ;
12- const { beforeAllCalls, afterAllCalls, joinPath, toggleCwdBetweenFullAndParentPath, tmpPath } = useTempPath ( actName , {
13- create : true ,
14- remove : true ,
15- cwd : true ,
16- cwdParent : true ,
17- } ) ;
13+ const { beforeAllCalls, afterAllCalls, joinPath, joinCwdPath, toggleCwdBetweenFullAndParentPath, tmpPath } =
14+ useTempPath ( actName , {
15+ create : true ,
16+ remove : true ,
17+ cwd : true ,
18+ cwdParent : true ,
19+ } ) ;
1820
1921const { lastErrorMessage } = useConsoleSpy ( ) ;
2022
@@ -150,4 +152,26 @@ describe('apify create', () => {
150152 // Check that .git directory does not exist
151153 expect ( existsSync ( joinPath ( '.git' ) ) ) . toBeFalsy ( ) ;
152154 } ) ;
155+
156+ it ( 'should skip git initialization when run from within an existing git repository' , async ( ) => {
157+ const ACT_TEMPLATE = 'project_empty' ;
158+
159+ // Create a .git folder in the parent directory (cwd) to simulate being inside a git repository
160+ await mkdir ( joinCwdPath ( '.git' ) , { recursive : true } ) ;
161+
162+ await testRunCommand ( CreateCommand , {
163+ args_actorName : actName ,
164+ flags_template : ACT_TEMPLATE ,
165+ flags_skipDependencyInstall : true ,
166+ } ) ;
167+
168+ toggleCwdBetweenFullAndParentPath ( ) ;
169+
170+ // Check that .git directory does not exist in the newly created actor directory
171+ expect ( existsSync ( joinCwdPath ( '.git' ) ) ) . toBeFalsy ( ) ;
172+
173+ // Cleanup
174+ toggleCwdBetweenFullAndParentPath ( ) ;
175+ await rm ( joinCwdPath ( '.git' ) , { recursive : true } ) ;
176+ } ) ;
153177} ) ;
0 commit comments