Skip to content

Commit 2b017e3

Browse files
committed
tests(init): add test for init in subdirectory
Add a test for running branchless init in a subdirectory.
1 parent 66528dd commit 2b017e3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

git-branchless/tests/test_init.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,49 @@ fn test_init_prompt_for_main_branch() -> eyre::Result<()> {
279279
Ok(())
280280
}
281281

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+
282325
#[cfg(unix)]
283326
#[test]
284327
fn test_main_branch_not_found_error_message() -> eyre::Result<()> {

0 commit comments

Comments
 (0)