Skip to content

Commit

Permalink
fix(hooks): use same branchless dir for all worktrees
Browse files Browse the repository at this point in the history
Previously, all worktrees would have their own event log, which means that they wouldn't agree on the set of visible commits. They would also have to recalculate the same DAG, etc. After this commit, they all share the same event log, etc.
  • Loading branch information
arxanas committed Oct 10, 2023
1 parent c8e4dd1 commit c981148
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion git-branchless-hook/tests/test_hook.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use lib::testing::{make_git, GitRunOptions};
use lib::testing::{make_git, make_git_worktree, GitRunOptions, GitWorktreeWrapper};

#[test]
fn test_is_rebase_underway() -> eyre::Result<()> {
Expand Down Expand Up @@ -148,3 +148,81 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> {

Ok(())
}

#[test]
fn test_hooks_in_worktree() -> eyre::Result<()> {
let git = make_git()?;
git.init_repo()?;
git.commit_file("test1", 1)?;
git.detach_head()?;

let GitWorktreeWrapper {
temp_dir: _temp_dir,
worktree,
} = make_git_worktree(&git, "new-worktree")?;

{
let (stdout, stderr) =
worktree.run(&["commit", "--allow-empty", "-m", "new empty commit"])?;
insta::assert_snapshot!(stderr, @r###"
branchless: processing 1 update: ref HEAD
branchless: processed commit: 1bed0d8 new empty commit
"###);
insta::assert_snapshot!(stdout, @r###"
[detached HEAD 1bed0d8] new empty commit
"###);
}

{
let stdout = git.smartlog()?;
insta::assert_snapshot!(stdout, @r###"
:
@ 62fc20d (master) create test1.txt
|
o 1bed0d8 new empty commit
"###);
}
{
let stdout = worktree.smartlog()?;
insta::assert_snapshot!(stdout, @r###"
:
O 62fc20d (master) create test1.txt
|
@ 1bed0d8 new empty commit
"###);
}

{
let (stdout, stderr) =
worktree.run(&["commit", "--amend", "--allow-empty", "--message", "amended"])?;
insta::assert_snapshot!(stderr, @r###"
branchless: processing 1 update: ref HEAD
branchless: processed commit: cc4313e amended
branchless: processing 1 rewritten commit
"###);
insta::assert_snapshot!(stdout, @r###"
[detached HEAD cc4313e] amended
Date: Thu Oct 29 12:34:56 2020 +0000
"###);
}
{
let stdout = git.smartlog()?;
insta::assert_snapshot!(stdout, @r###"
:
@ 62fc20d (master) create test1.txt
|
o cc4313e amended
"###);
}
{
let stdout = worktree.smartlog()?;
insta::assert_snapshot!(stdout, @r###"
:
O 62fc20d (master) create test1.txt
|
@ cc4313e amended
"###);
}

Ok(())
}

0 comments on commit c981148

Please sign in to comment.