@@ -279,6 +279,99 @@ fn test_init_prompt_for_main_branch() -> eyre::Result<()> {
279
279
Ok ( ( ) )
280
280
}
281
281
282
+ #[ cfg( unix) ]
283
+ #[ test]
284
+ fn test_init_in_subdir ( ) -> eyre:: Result < ( ) > {
285
+ let git = make_git ( ) ?;
286
+
287
+ if !git. supports_reference_transactions ( ) ? {
288
+ return Ok ( ( ) ) ;
289
+ }
290
+
291
+ git. init_repo_with_options ( & GitInitOptions {
292
+ run_branchless_init : false ,
293
+ ..Default :: default ( )
294
+ } ) ?;
295
+
296
+ let subdir = git. repo_path . join ( "subdir" ) ;
297
+ std:: fs:: create_dir ( & subdir) ?;
298
+
299
+ {
300
+ let ( stdout, stderr) = git. branchless_with_options (
301
+ "init" ,
302
+ & [ ] ,
303
+ & GitRunOptions {
304
+ working_dir : Some ( subdir) ,
305
+ ..Default :: default ( )
306
+ } ,
307
+ ) ?;
308
+ insta:: assert_snapshot!( stderr, @"" ) ;
309
+ insta:: assert_snapshot!( stdout, @r###"
310
+ Created config file at <repo-path>/.git/branchless/config
311
+ Auto-detected your main branch as: master
312
+ If this is incorrect, run: git branchless init --main-branch <branch>
313
+ Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
314
+ Successfully installed git-branchless.
315
+ To uninstall, run: git branchless init --uninstall
316
+ "### ) ;
317
+ }
318
+
319
+ let hook_path = git. repo_path . join ( ".git" ) . join ( "hooks" ) . join ( "post-commit" ) ;
320
+ assert ! ( hook_path. exists( ) ) ;
321
+
322
+ Ok ( ( ) )
323
+ }
324
+
325
+ #[ cfg( unix) ]
326
+ #[ test]
327
+ fn test_init_in_subdir_with_hooks_path ( ) -> eyre:: Result < ( ) > {
328
+ let git = make_git ( ) ?;
329
+
330
+ if !git. supports_reference_transactions ( ) ? {
331
+ return Ok ( ( ) ) ;
332
+ }
333
+
334
+ git. init_repo_with_options ( & GitInitOptions {
335
+ run_branchless_init : false ,
336
+ ..Default :: default ( )
337
+ } ) ?;
338
+
339
+ let hooks_path = git. repo_path . join ( "my-hooks" ) ;
340
+ std:: fs:: create_dir ( & hooks_path) ?;
341
+ git. run ( & [ "config" , "core.hooksPath" , "my-hooks" ] ) ?;
342
+
343
+ let subdir = git. repo_path . join ( "subdir" ) ;
344
+ std:: fs:: create_dir ( & subdir) ?;
345
+
346
+ {
347
+ let ( stdout, stderr) = git. branchless_with_options (
348
+ "init" ,
349
+ & [ ] ,
350
+ & GitRunOptions {
351
+ working_dir : Some ( subdir) ,
352
+ ..Default :: default ( )
353
+ } ,
354
+ ) ?;
355
+ insta:: assert_snapshot!( stderr, @"" ) ;
356
+ insta:: assert_snapshot!( stdout, @r###"
357
+ Created config file at <repo-path>/.git/branchless/config
358
+ Auto-detected your main branch as: master
359
+ If this is incorrect, run: git branchless init --main-branch <branch>
360
+ Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
361
+ Warning: the configuration value core.hooksPath was set to: <repo-path>/my-hooks,
362
+ which is not the expected default value of: <repo-path>/.git/hooks
363
+ The Git hooks above may have been installed to an unexpected global location.
364
+ Successfully installed git-branchless.
365
+ To uninstall, run: git branchless init --uninstall
366
+ "### ) ;
367
+ }
368
+
369
+ let hook_path = hooks_path. join ( "post-commit" ) ;
370
+ assert ! ( hook_path. exists( ) ) ;
371
+
372
+ Ok ( ( ) )
373
+ }
374
+
282
375
#[ cfg( unix) ]
283
376
#[ test]
284
377
fn test_main_branch_not_found_error_message ( ) -> eyre:: Result < ( ) > {
@@ -547,7 +640,7 @@ fn test_init_core_hooks_path_warning() -> eyre::Result<()> {
547
640
Auto-detected your main branch as: master
548
641
If this is incorrect, run: git branchless init --main-branch <branch>
549
642
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
550
- Warning: the configuration value core.hooksPath was set to: my-hooks,
643
+ Warning: the configuration value core.hooksPath was set to: <repo-path>/ my-hooks,
551
644
which is not the expected default value of: <repo-path>/.git/hooks
552
645
The Git hooks above may have been installed to an unexpected global location.
553
646
Successfully installed git-branchless.
@@ -600,7 +693,7 @@ hooksPath = my-hooks
600
693
Auto-detected your main branch as: master
601
694
If this is incorrect, run: git branchless init --main-branch <branch>
602
695
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
603
- Warning: the configuration value core.hooksPath was set to: my-hooks,
696
+ Warning: the configuration value core.hooksPath was set to: <repo-path>/ my-hooks,
604
697
which is not the expected default value of: <repo-path>/.git/hooks
605
698
The Git hooks above may have been installed to an unexpected global location.
606
699
Successfully installed git-branchless.
0 commit comments