dura
dura copied to clipboard
Dura fails to capture anything if a worktree is present as a subdir of the working directory
If you have an unignored worktree checked out in a subdirectory of the main working directory of a git repository, Dura will fail to capture any changes (whether by watch or capture).
Consider this example:
$ git init
$ echo 'beep' > boop
$ git add . && git commit -m 'initial commit'
$ dura capture # works correctly at this point
$ git worktree add -d wrktree HEAD
$ dura capture
Dura capture failed: invalid path: 'wrktree/'; class=Index (10)
If wrktree/ is added to .gitignore, Dura continues working fine.
This is admittedly a bit of an edge case, and perhaps an unconventional way to use worktrees, but Dura failing in this situation can also be a surprise to the user.
Thanks for reporting. I don't have much time to look at it this weekend, but I might next week. I'm not quite sure what's going on.
It seems to be an issue with git2. A minimal example that reproduces this is:
use git2::{Repository, IndexAddOption};
fn main() {
let repo = Repository::open("./").unwrap();
let mut index = repo.index().unwrap();
index.add_all(["*"].iter(), IndexAddOption::DEFAULT, None).unwrap();
}
I'm not sure if the git2/libgit2 behavior here is a bug. Git itself when asked to git add -A in this situation adds the repository as a subproject link and prints a hint about adding it as a submodule instead.
This is a git2-rs behaviour which returns Result::Err when adding another git repo inside a subdirectory.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -1, klass: 10, message: "invalid path: 'foo-git/'" }', src/main.rs:6:64
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Not sure if the preferred behaviour for dura would be ignoring these paths or adding them into consideration for checking the diff. Personally, I'd probably ask dura to watch the repos in subdirectory separately.
The ideal scenario I guess would be a include_sub_repos setting (or something to that effect) so you can toggle it. I think that should default to false.
I'd probably ask dura to watch the repos in subdirectory separately
Do you think using the existing include option would be a good way of doing this, or would that risk confusion? Would it be safer to just stick to adding an entire new repo entry in the config?