@@ -2,7 +2,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'n
22import path from 'node:path' ;
33import { expect , test } from 'rstack/test' ;
44import { installHooks } from '../../src/setup/install.ts' ;
5- import { runHook , withRepository , writeHook , writeInit } from './helpers.ts' ;
5+ import { runGitHook , runHook , withRepository , writeHook , writeInit } from './helpers.ts' ;
66
77test ( 'loads user init and project binaries' , ( ) => {
88 withRepository ( ( cwd ) => {
@@ -35,6 +35,36 @@ rstack-hook-command
3535 } ) ;
3636} ) ;
3737
38+ test ( 'preserves cwd-sensitive hook arguments for a nested project' , ( ) => {
39+ withRepository ( ( cwd ) => {
40+ const projectDirectory = path . join ( cwd , 'frontend' ) ;
41+ const messagePath = '.git/COMMIT_EDITMSG' ;
42+ mkdirSync ( projectDirectory ) ;
43+ writeFileSync ( path . join ( cwd , messagePath ) , 'commit message\n' ) ;
44+
45+ expect ( installHooks ( { cwd : projectDirectory } ) . status ) . toBe ( 'installed' ) ;
46+
47+ for ( const name of [ 'applypatch-msg' , 'commit-msg' , 'prepare-commit-msg' ] ) {
48+ writeFileSync ( path . join ( cwd , '.rstack' , 'hooks' , name ) , 'cat "$1"\n' ) ;
49+
50+ expect ( runGitHook ( cwd , name , [ messagePath ] ) ) . toMatchObject ( {
51+ status : 0 ,
52+ stderr : 'commit message\n' ,
53+ } ) ;
54+ }
55+
56+ mkdirSync ( path . join ( cwd , 'remote.git' ) ) ;
57+ writeFileSync (
58+ path . join ( cwd , '.rstack' , 'hooks' , 'pre-push' ) ,
59+ '[ -d "$2" ] || [ "$2" = "git@example.com:repo.git" ]\n' ,
60+ ) ;
61+
62+ for ( const remote of [ 'remote.git' , 'git@example.com:repo.git' ] ) {
63+ expect ( runGitHook ( cwd , 'pre-push' , [ 'origin' , remote ] ) . status ) . toBe ( 0 ) ;
64+ }
65+ } ) ;
66+ } ) ;
67+
3868test ( 'skips user hooks when disabled by the environment or init' , ( ) => {
3969 withRepository ( ( cwd ) => {
4070 writeHook ( cwd , 'echo ran >> hook-ran\n' ) ;
@@ -47,5 +77,8 @@ test('skips user hooks when disabled by the environment or init', () => {
4777
4878 expect ( runHook ( cwd ) . status ) . toBe ( 0 ) ;
4979 expect ( existsSync ( path . join ( cwd , 'hook-ran' ) ) ) . toBe ( false ) ;
80+
81+ writeFileSync ( path . join ( cwd , '.rstack' , 'hooks' , 'commit-msg' ) , 'exit 1\n' ) ;
82+ expect ( runGitHook ( cwd , 'commit-msg' , [ ] ) . status ) . toBe ( 0 ) ;
5083 } ) ;
5184} ) ;
0 commit comments