Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dura fails to capture anything if a worktree is present as a subdir of the working directory #89

Open
DeeUnderscore opened this issue Jan 27, 2022 · 4 comments

Comments

@DeeUnderscore
Copy link
Contributor

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.

@tkellogg
Copy link
Owner

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.

@DeeUnderscore
Copy link
Contributor Author

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.

@dswij
Copy link
Contributor

dswij commented Jan 30, 2022

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.

@JakeStanger
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants