@@ -11,6 +11,15 @@ const REPO_ROOT = resolve(import.meta.dirname, "..");
1111const SCRIPT = join ( REPO_ROOT , "scripts" , "enable-hooks.ts" ) ;
1212const repositories : string [ ] = [ ] ;
1313
14+ /**
15+ * Git exports `GIT_DIR` and its siblings to every hook process, and they outrank a child's `cwd`.
16+ * Inherited, they would point both the script under test and the assertions at the repository the
17+ * hook is running in rather than at the clone made below.
18+ */
19+ const ENV = Object . fromEntries (
20+ Object . entries ( process . env ) . filter ( ( [ key ] ) => ! key . startsWith ( "GIT_" ) ) ,
21+ ) ;
22+
1423after ( ( ) => {
1524 for ( const repository of repositories ) rmSync ( repository , { recursive : true , force : true } ) ;
1625} ) ;
@@ -24,9 +33,7 @@ function clone(): { repository: string; git: (...args: string[]) => string } {
2433 cwd : repository ,
2534 encoding : "utf8" ,
2635 maxBuffer : CAPTURE_LIMIT_BYTES ,
27- env : Object . fromEntries (
28- Object . entries ( process . env ) . filter ( ( [ key ] ) => ! key . startsWith ( "GIT_" ) ) ,
29- ) ,
36+ env : ENV ,
3037 } ) . trim ( ) ;
3138 git ( "init" , "--quiet" ) ;
3239 git ( "config" , "core.hooksPath" , ".husky/_" ) ;
@@ -40,10 +47,11 @@ void test("an install moves Git from an earlier hooks directory to the dispatche
4047 cwd : repository ,
4148 encoding : "utf8" ,
4249 maxBuffer : CAPTURE_LIMIT_BYTES ,
50+ env : ENV ,
4351 } ) ;
4452 assert . equal ( result . status , 0 , `${ result . stdout } ${ result . stderr } ` ) ;
4553 assert . equal ( git ( "config" , "core.hooksPath" ) , ".vite-hooks/_" ) ;
46- const again = spawnSync ( "node" , [ SCRIPT ] , { cwd : repository , encoding : "utf8" } ) ;
54+ const again = spawnSync ( "node" , [ SCRIPT ] , { cwd : repository , encoding : "utf8" , env : ENV } ) ;
4755 assert . equal ( again . status , 0 , `${ again . stdout } ${ again . stderr } ` ) ;
4856 assert . equal ( git ( "config" , "core.hooksPath" ) , ".vite-hooks/_" ) ;
4957} ) ;
0 commit comments