Skip to content

Commit c981148

Browse files
committed
fix(hooks): use same branchless dir for all worktrees
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.
1 parent c8e4dd1 commit c981148

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

git-branchless-hook/tests/test_hook.rs

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lib::testing::{make_git, GitRunOptions};
1+
use lib::testing::{make_git, make_git_worktree, GitRunOptions, GitWorktreeWrapper};
22

33
#[test]
44
fn test_is_rebase_underway() -> eyre::Result<()> {
@@ -148,3 +148,81 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> {
148148

149149
Ok(())
150150
}
151+
152+
#[test]
153+
fn test_hooks_in_worktree() -> eyre::Result<()> {
154+
let git = make_git()?;
155+
git.init_repo()?;
156+
git.commit_file("test1", 1)?;
157+
git.detach_head()?;
158+
159+
let GitWorktreeWrapper {
160+
temp_dir: _temp_dir,
161+
worktree,
162+
} = make_git_worktree(&git, "new-worktree")?;
163+
164+
{
165+
let (stdout, stderr) =
166+
worktree.run(&["commit", "--allow-empty", "-m", "new empty commit"])?;
167+
insta::assert_snapshot!(stderr, @r###"
168+
branchless: processing 1 update: ref HEAD
169+
branchless: processed commit: 1bed0d8 new empty commit
170+
"###);
171+
insta::assert_snapshot!(stdout, @r###"
172+
[detached HEAD 1bed0d8] new empty commit
173+
"###);
174+
}
175+
176+
{
177+
let stdout = git.smartlog()?;
178+
insta::assert_snapshot!(stdout, @r###"
179+
:
180+
@ 62fc20d (master) create test1.txt
181+
|
182+
o 1bed0d8 new empty commit
183+
"###);
184+
}
185+
{
186+
let stdout = worktree.smartlog()?;
187+
insta::assert_snapshot!(stdout, @r###"
188+
:
189+
O 62fc20d (master) create test1.txt
190+
|
191+
@ 1bed0d8 new empty commit
192+
"###);
193+
}
194+
195+
{
196+
let (stdout, stderr) =
197+
worktree.run(&["commit", "--amend", "--allow-empty", "--message", "amended"])?;
198+
insta::assert_snapshot!(stderr, @r###"
199+
branchless: processing 1 update: ref HEAD
200+
branchless: processed commit: cc4313e amended
201+
branchless: processing 1 rewritten commit
202+
"###);
203+
insta::assert_snapshot!(stdout, @r###"
204+
[detached HEAD cc4313e] amended
205+
Date: Thu Oct 29 12:34:56 2020 +0000
206+
"###);
207+
}
208+
{
209+
let stdout = git.smartlog()?;
210+
insta::assert_snapshot!(stdout, @r###"
211+
:
212+
@ 62fc20d (master) create test1.txt
213+
|
214+
o cc4313e amended
215+
"###);
216+
}
217+
{
218+
let stdout = worktree.smartlog()?;
219+
insta::assert_snapshot!(stdout, @r###"
220+
:
221+
O 62fc20d (master) create test1.txt
222+
|
223+
@ cc4313e amended
224+
"###);
225+
}
226+
227+
Ok(())
228+
}

0 commit comments

Comments
 (0)