git-branchless
git-branchless copied to clipboard
init doesn't complete successfully in worktree
Description of the bug
When installing branchless, init succeeds but results in a non-working state if run in a worktree:
git branchless init --uninstall
git worktree add -b testworktree ~/worktrees/testworktree
cd ~/worktrees/testworktree
git branchless init
git sl # doesn't work
cd - # Back to main worktree
git branchless init
cd - # Back to testworktree
git sl # works
The workaround is to run init in the main worktree, and then branchless works in other worktrees as well. I think there should be at least a warning about this but ideally init would work when run within a worktree.
Expected behavior
init works when within any worktree
Actual behavior
init only works when performed in main worktree
Version of rustc
rustc 1.63.0 (4b91a6ea7 2022-08-08)
Automated bug report
No response
Version of git-branchless
git-branchless 0.4.0
Version of git
git version 2.37.2
I also experiance this problem.
Hi @xEtherealx, thanks for reporting. It looks like it would be possible to determine if the repository is a worktree using Repository::is_worktree
, but I'm not quite sure how to find the main repository from that. If you want to make an attempt to fix this, you can find the relevant code in init.rs
.
@xEtherealx @cloudhan can you try with #588 and see if it works now?
By the way, I haven't tested git-branchless with worktrees, so there might be some issues like https://github.com/arxanas/git-branchless/issues/215.
@arxanas I just circled back on this with the latest master and init is failing in a different way now (logs below).
Edit: I think this is a different issue; I'm able to init with a simpler use case. I'll open a new ticket if I can't resolve it.
❯ git branchless init
The application panicked (crashed).
Message: A fatal error occurred:
0: could not open repository: could not find repository from '<myrepo>'; class=Repository (6); code=NotFound (-3)
1: could not find repository from '<myrepo>'; class=Repository (6); code=NotFound (-3)
Location:
git-branchless-init/src/lib.rs:589
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⋮ 3 frames hidden ⋮
4: git_branchless_init::command_init::h85f4c92a6835c724
at <unknown source file>:<unknown line>
5: git_branchless_init::command_main::hcf13cd11b485e2dd
at <unknown source file>:<unknown line>
6: git_branchless::commands::command_main::ha3994300ed87cdc3
at <unknown source file>:<unknown line>
7: git_branchless_invoke::do_main_and_drop_locals::ha19c4a129cdbabf9
at <unknown source file>:<unknown line>
8: git_branchless::commands::main::h2573813207db7dad
at <unknown source file>:<unknown line>
9: std::sys_common::backtrace::__rust_begin_short_backtrace::h21c2fd2ef03ce226
at <unknown source file>:<unknown line>
10: std::rt::lang_start::{{closure}}::hc09d9c6b25f3b076
at <unknown source file>:<unknown line>
11: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb69be6e0857c6cfb
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283
12: std::panicking::try::do_call::h396dfc441ee9c786
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492
13: std::panicking::try::h6cdda972d28b3a4f
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456
14: std::panic::catch_unwind::h376039ec264e8ef9
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137
15: std::rt::lang_start_internal::{{closure}}::hc94720ca3d4cb727
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148
16: std::panicking::try::do_call::h2422fb95933fa2d5
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492
17: std::panicking::try::h488286b5ec8333ff
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456
18: std::panic::catch_unwind::h81636549836d2a25
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137
19: std::rt::lang_start_internal::h6ba1bb743c1e9df9
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148
20: main<unknown>
at <unknown source file>:<unknown line>
21: __libc_start_main<unknown>
at /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
22: _start<unknown>
at <unknown source file>:<unknown line>
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
Location: git-branchless/src/commands/mod.rs:255
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⋮ 8 frames hidden ⋮
9: core::result::Result<T,E>::expect::hb55401d2b6ddac12
at <unknown source file>:<unknown line>
10: git_branchless::commands::main::h2573813207db7dad
at <unknown source file>:<unknown line>
11: std::sys_common::backtrace::__rust_begin_short_backtrace::h21c2fd2ef03ce226
at <unknown source file>:<unknown line>
12: std::rt::lang_start::{{closure}}::hc09d9c6b25f3b076
at <unknown source file>:<unknown line>
13: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb69be6e0857c6cfb
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283
14: std::panicking::try::do_call::h396dfc441ee9c786
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492
15: std::panicking::try::h6cdda972d28b3a4f
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456
16: std::panic::catch_unwind::h376039ec264e8ef9
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137
17: std::rt::lang_start_internal::{{closure}}::hc94720ca3d4cb727
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148
18: std::panicking::try::do_call::h2422fb95933fa2d5
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492
19: std::panicking::try::h488286b5ec8333ff
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456
20: std::panic::catch_unwind::h81636549836d2a25
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137
21: std::rt::lang_start_internal::h6ba1bb743c1e9df9
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148
22: main<unknown>
at <unknown source file>:<unknown line>
23: __libc_start_main<unknown>
at /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
24: _start<unknown>
at <unknown source file>:<unknown line>