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

Respect env variables when running gix #1639

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

cruessler
Copy link
Contributor

While working on gix blame I found that, for testing purposes, I wanted to run env GIT_WORK_TREE=… gix blame which did not work as expected. This PR changes that. I don’t know whether it was intentional not to take env variables into account. If it was, feel free to just close this PR!

@Byron
Copy link
Member

Byron commented Oct 21, 2024

Thanks a lot, it's appreciated!

It doesn't seem to be working though and I think I know why. In theory, it should already be working anyway, but… let me try to make this work, I will push on top (without force).

Otherwise it can happen that `&mut |section| {...}` needs to be borrowed
for `'static`, which makes it impossible to use.

The coercion seems to be messing with lifetimes.
Now it's picked up durign initialization.
@Byron
Copy link
Member

Byron commented Oct 21, 2024

This was surprisingly tricky 😅.

In short, here is what happened.

  • core.worktree can be used to set the worktree, but it's meant to be put into a git configuration file, and relative paths are relative to that (so .. would be the normal worktree, ../../ would be one above), which is unintuitive when provided via gix -c core.worktree=.., which seems to do nothing.
    • git -c core.worktree is completely ignored
  • GIT_WORK_TREE wasn't wired in the env-init sequence, which allows it to become accessible through git configuration. try GIT_WORK_TREE=.. gix config to see what I mean - now that it's fixed it shows up.
  • The cleanest solution was to check where the now wired core.worktree value is coming from so it can either be relative to the git dir or to the current dir.
  • lastly, there was a Rust issue due to &dyn FnMut which made me go back to using impl for the filter.

Now it should work though, and I think it's intuitive as well despite the quite different functioning of repository discovery (compared to Git). That should be fine, as both Git and gitoxide still find the same repository/worktree, but gix now can also do -c core.worktree overrides.

@Byron Byron enabled auto-merge October 21, 2024 18:28
@Byron Byron merged commit 48aa74b into GitoxideLabs:main Oct 21, 2024
16 checks passed
@cruessler
Copy link
Contributor Author

Fascinating! This looked like such an innocuous change! :-)

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

Successfully merging this pull request may close these issues.

2 participants