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

Fix+improve Git repository lookup (GIT_DIR; GIT_CEILING_DIRECTORIES) #117

Merged
merged 6 commits into from
Aug 12, 2023
Merged

Fix+improve Git repository lookup (GIT_DIR; GIT_CEILING_DIRECTORIES) #117

merged 6 commits into from
Aug 12, 2023

Conversation

mentalisttraceur
Copy link
Contributor

@mentalisttraceur mentalisttraceur commented Aug 11, 2023

This PR fixes the GIT_DIR-related issues mentioned in #115, and also adds support for GIT_CEILING_DIRECTORIES.

(Normally I'd do those two things in separate PRs, but every line that the latter changes is also changed by the former - I put them in separate commits though, so unless you squash when merging, they'll stay as cleanly separated atoms of change in the history.)

GIT_CEILING_DIRECTORIES is actually my main goal here. I depend on Git's ceiling directory feature every day to keep a lot of my (exa|eza) --long --git ... invocations from freezing up (for 2-3 seconds at a time in the worst case). So I had done that change first (a couple days ago, after I realized that my PR to the Exa upstream probably wasn't going to move), then while testing that I noticed the GIT_DIR stuff.

These changes are the first Rust code I've ever written, so if there's anything unusually off from how Rust code Is Supposed To Be, please feel free to let me know so I can fix it!

@cafkafk cafkafk self-requested a review August 11, 2023 06:59
@mentalisttraceur
Copy link
Contributor Author

mentalisttraceur commented Aug 11, 2023

One day I'd like to follow this up by adding tests for all the cases listed in #115, but I don't have the time or patience for it just yet.

Partially because they would have to be in xtests/, which only run in Vagrant unless we bring in ogham/exa/pull/1230, and the Vagrant stuff fails to start for me (and at least one other person as far as I've seen).

The manual testing I've done so far usually goes like this:

mkdir /tmp/test
mkdir /tmp/test/git-1
mkdir /tmp/test/git-2
mkdir /tmp/test/not-git
(cd /tmp/test/git-1 && git init && touch a b && git add a)
(cd /tmp/test/git-2 && git init && touch c d && git add d)
(cd /tmp/test/not-git && touch e f)

And then from there I cd around, calling eza --long --git [../(git-1|git-2|not-git)] with and without GIT_DIR.

For GIT_CEILING_DIRECTORIES, I create /tmp/test/nested, move git-1, git-2, and not-git into nested, and then hit /tmp/test itself with a git init. Then I redo some or all of the cases I'd test with and without GIT_DIR in the three now-nested directories, twice, once with GIT_CEILING_DIRECTORIES=/tmp/test and once without.

I think that would basically catch all the correct cases. Since the git stuff is a silently-gracefully-degrates feature, there aren't really any specific failure behaviors to check for. (Although I personally check that GIT_DIR set to non-existent and not-a-repo paths is gracefully ignored, since that seems like a reasonable-enough tolerance for something like Exa/Eza to have.)

mentalisttraceur and others added 3 commits August 11, 2023 12:58
1. This fixes the case where GIT_DIR is not set,
   Exa/Eza is executed inside of a repo, but an
   argument path is outside of that repo. (The
   current working directory's Git repo was
   getting checked instead of whatever the Git
   repo for that path was. Now it will check
   correctly search for that path's repo again.)

2. Same as 1, but GIT_DIR is set, but a path is
   is outside of that repo. (GIT_DIR's repo was
   getting checked instead of whatever the Git
   repo for that path was. Now it will check
   GIT_DIR's repo for status first, but if a
   path is not in that repo, it will check for
   a repo for that path the normal way.)
Signed-off-by: Christina Sørensen <[email protected]>
@cafkafk
Copy link
Member

cafkafk commented Aug 11, 2023

(Normally I'd do those two things in separate PRs, but every line that the latter changes is also changed by the former - I put them in separate commits though, so unless you squash when merging, they'll stay as cleanly separated atoms of change in the history.)

I think this was the right approach here. Having the changes atomized is nice, but they're so closely related that keeping them in the same PR makes sense.

GIT_CEILING_DIRECTORIES

Never heard of this env var, seems super useful thou, TIL.

Partially because they would have to be in xtests/, which only run in Vagrant unless we bring in ogham/exa#1230, and the Vagrant stuff fails to start for me (and at least one other person as far as I've seen).

Yea, something like this is my priority right now, although I'm not sure it will be that specific PR. I think I'm gonna set something up after #101 is done, but that's annoyingly being blocked by a issue I'm working on...

These changes are the first Rust code I've ever written, so if there's anything unusually off from how Rust code Is Supposed To Be, please feel free to let me know so I can fix it!

I don't think there's anything super rust specific. I did remove the unused var, just to keep it a little tidy. Only other thing in this regard is that I changed your commit summaries to conventional commit.

@cafkafk
Copy link
Member

cafkafk commented Aug 11, 2023

@sbatial are you available for testing this? (see: #117 (comment))

@sbatial
Copy link
Collaborator

sbatial commented Aug 11, 2023

Yea.
I can look into it

@mentalisttraceur
Copy link
Contributor Author

mentalisttraceur commented Aug 11, 2023

I did remove the unused var, just to keep it a little tidy.

Cool. That was how I did it at first, but then I switched it to a variable because Exa's build was causing a "trivial cast" lint warning about it (I just assumed you had the same warning still enabled in Eza).

Only other thing in this regard is that I changed your commit summaries to conventional commit.

Oh cool, I'm glad there are well-defined conventions gaining much traction and slick websites documenting them. Thanks for sharing! Also, sorry I didn't notice and match it - I had looked at how Exa was doing it previously and didn't see any obvious convention, forgot to consciously check if y'all were doing it differently in this fork. Might end up adopting it by default in my projects - looking it over I have a mostly positive reaction.

Aside: couple negative opinionated nits re: choices in Conventional Commit.

  1. "!" is
    1. cryptic/opaque/not-self-describing shorthand for breaking changes,
    2. is easy overlook
    3. is one typo away from being invisibly lost,
    4. is one bit flip away from being ambiguous if you're looking at a breaking change or a non-breaking change and a typo, and
    5. I'd love to know how things like screen readers handle it;
  2. "feat" instead of "feature" is
    1. yet another unfortunate case of enshrining in standard the bad practice of abbreviating when it has no benefit but shaving off a whole three characters like this is the 1970s and we are Programmers(tm), and
    2. "feat" is its own word with a different meaning.

@mentalisttraceur
Copy link
Contributor Author

Oh, I don't have a strong preference about this, but I would've thought both of my commits are "fix" type rather than one the GIT_DIR one being "refactor" type?

To me a refactor is something that doesn't change the observable behavior (lesser in API impact than a fix)?

@sbatial
Copy link
Collaborator

sbatial commented Aug 12, 2023

I've looked into it and it looks good on first inspection.
But as I'm not really fully awake right now I will get back to you in a few hours when I trust myself to be thorough 😅

cafkafk and others added 3 commits August 12, 2023 17:07
Co-authored-by: Alexander Kozhevnikov <[email protected]>
Signed-off-by: Christina Sørensen <[email protected]>
@cafkafk
Copy link
Member

cafkafk commented Aug 12, 2023

That was how I did it at first, but then ogham/exa#1226 (comment) (I just assumed you had the same warning still enabled in Eza).

After #119 and #120 we now do!

About nits on conventional commits: valid, agree on most, but I don't think straying from it is a good idea because:

  1. If formatted well, we get free change logs.
  2. People don't need to learn our hypothethical idiosyncratic fixes just to commit to eza.
  3. xkcd 927

The accessibility concern is very valid thou, I guess we could require the BREAKING CHANGE: footer if ! is present, perhaps we might get someone with a screen reader to tell us how annoying the ! is, and only use the footer.

To me a refactor is something that doesn't change the observable behavior (lesser in API impact than a fix)?

Perhaps this could have been a feat if anything. I don't wanna get too nit picky with this thou, but I'll consider for the next time.

@cafkafk
Copy link
Member

cafkafk commented Aug 12, 2023

I've looked into it and it looks good on first inspection. But as I'm not really fully awake right now I will get back to you in a few hours when I trust myself to be thorough sweat_smile

I also did some testing on this, but tbh I don't have the full mental model of this in my head yet, so I think I'm just gonna say this is reasonably tested and then hope if it breaks users will be quick to open an issue.

Copy link
Member

@cafkafk cafkafk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested to reasonable extend

@cafkafk cafkafk merged commit 9d69206 into eza-community:main Aug 12, 2023
@sbatial
Copy link
Collaborator

sbatial commented Aug 12, 2023

All right.... I've gone over all the cases now I think.

  1. GIT_CEILING_DIRECTORIES seems to work with the new changes and to be consistent with the tests on GIT_DIR.

  2. I've done my best to note my results for future reference on what has been checked:

Behaviours (while `GIT_DIR` is set if not stated otherwise)

Outside a repo

main

Show git column but only an actual state for the GIT_DIR folder/the folder containing it.

PR 117

Show no git column even with --git.

Inside the same dir to which GIT_DIR is set

main

Show file status' as expected
The same as with no env var

PR 117

Show file status' as expected
The same as with no env var

Inside another repo

main

show no status (presumably the status relative to GIT_DIR)
differs from no env var

PR 117

show status of the repo we are in
The same as with no env var

inside a folder with no repo (and not a parent of GIT_DIR)

main

show no status (presumably the status relative to GIT_DIR)
differs from no env var (which shows no git column at all)

PR 117

show no git column at all
differs from no env var

Inside a subrepo of GIT_DIR

main

show no status (which does somewhat match with what's expected from a subrepo (if in the parent)?! the parent should not care about it)
differs from no env var (which shows the status of the repo we are in)

PR 117

show status of subrepo we are in
same as without env var

we are in the same path as GIT_DIR is (or would be) set to but list ../

main

print no status for everyting but GIT_DIR
same as without env var

PR 117

print no git column
same as without env var

Regarding tests: I think this can be merged (well it just has been so...) but I think this is a very good case where tests would make sense to prevent having the same misbehaviour again and needing the same extensive manual testing.

P.S.: And now my head hurts... 🥴

@sbatial
Copy link
Collaborator

sbatial commented Aug 12, 2023

I've looked into it and it looks good on first inspection. But as I'm not really fully awake right now I will get back to you in a few hours when I trust myself to be thorough sweat_smile

I also did some testing on this, but tbh I don't have the full mental model of this in my head yet, so I think I'm just gonna say this is reasonably tested and then hope if it breaks users will be quick to open an issue.

I was just about to send in my results so.. 😅 But yes. I came to the same conclusion.

@cafkafk
Copy link
Member

cafkafk commented Aug 12, 2023

I was just about to send in my results so.. sweat_smile But yes. I came to the same conclusion.

I think my message initially said I was still interested in how you tested it, but I ctrl-w'ed and lost my message so I rewrote a worse version.

Regarding tests: I think this can be merged (well it just has been so...) but I think this is a very good case where tests would make sense to prevent having the same misbehaviour again and needing the same extensive manual testing.

Tests would save us so many head hurts, and they're very much one of my top priorities to get a good solution to. We just need to find a good way to do them, and I'm not sure vagrant is it...

@mentalisttraceur
Copy link
Contributor Author

Nice! Thank you both for so thoroughly double-checking my work! I hope it was clear by

The manual testing I've done so far [...]

that I had already done some manual testing too (if it wasn't, sorry if I caused you to do more testing than you would've).

In any case, I really appreciate you testing it too, because I was rather tired by the time I finished with the last version of the change and refactoring.

Anyway, glad to see this merged, thanks and best of luck with other Eza work!

@sbatial
Copy link
Collaborator

sbatial commented Aug 14, 2023

We just need to find a good way to do them, and I'm not sure vagrant is it

Yeah. I don't have much experience with either Docker or Vagrant (but at least a little with Docker).
As it currently stands I feel like the way to go would be to see if ogham/exa#1230 works (or to try to get it to) and then go with Docker.

@iamkroot
Copy link

iamkroot commented Aug 29, 2023

inside a folder with no repo (and not a parent of GIT_DIR)

main

show no status (presumably the status relative to GIT_DIR) differs from no env var (which shows no git column at all)

PR 117

show no git column at all differs from no env var

I'm a bit confused about this outcome. If I'm in a directory without a repo, and which is not directly related to GIT_DIR, BUT some of the files are being tracked by the GIT_DIR repo, I'd like to see their status. This PR seems to cause eza to ignore such files completely :(

In my case, this is the folder structure (this is the usual workflow when using yadm)

  • $HOME/.local/share/yadm/repo.git/ is the git repo, and the value of GIT_DIR env var
  • GIT_WORK_TREE is set to $HOME
  • So, any files inside $HOME can be tracked by this git repo. Eg: I can go to $HOME/.config, run eza --git --long and expect to see the git column.

Feels like any solution will be incomplete unless we also start understanding GIT_WORK_TREE

EDIT: see longer comment in #115 (comment)

@mentalisttraceur
Copy link
Contributor Author

If I'm in a directory without a repo, and which is not directly related to GIT_DIR, BUT some of the files are being tracked by the GIT_DIR repo [...] This PR seems to cause eza to ignore such files completely :(

Did you actually check?

I can't remember/check right this moment, but that doesn't sound like behavior that I would've implemented. In fact that sounds like behavior I would've considered too obviously wrong to be acceptable , since having this work is exactly the point of GIT_DIR.

@iamkroot
Copy link

Did you actually check?

Yup, in the setup described above. I also rolled back to v0.10.6 and it started working as before. So definitely caused by this change.

@iamkroot
Copy link

I can't remember/check right this moment, but that doesn't sound like behavior that I would've implemented. In fact that sounds like behavior I would've considered too obviously wrong to be acceptable , since having this work is exactly the point of GIT_DIR.

unfortunately, this behaviour is the result of the "ideal" behaviour described for case 2 in the linked issue. See my latest comment there.

@mentalisttraceur
Copy link
Contributor Author

Hmm... I guess I didn't test that case properly and I misunderstood/mispredicted how libgit2 would work in that case. Sorry.

I'll try to look into it this week.

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

Successfully merging this pull request may close these issues.

Finding Git directory was broken by adding GIT_DIR support in the general case
4 participants