-
-
Notifications
You must be signed in to change notification settings - Fork 623
feat: support custom $GIT_DIR #2263
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
Conversation
We added such functionality in #2012 however that resulted in a regression and was backed out. There's a PR open now to reintroduce that functionality #2194 This does seem a lot simpler: just using I'm not sure how this works in test case 3; I'll test it out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately there are also extra regular file system watchers created for the custom git directory.
Example with GIT_DIR=/home/alex/2263/nvt/.cgd
You can see two watchers for .cgd
. The first one is the desired one, with the filtered set of files.
[2023-06-12 15:35:52] [watcher] Watcher:new '/home/alex/2263/nvt' nil
[2023-06-12 15:35:52] [watcher] Event:new '/home/alex/2263/nvt'
[2023-06-12 15:35:52] [watcher] Event:start '/home/alex/2263/nvt'
[2023-06-12 15:35:52] [git] { "git", "-C", "/home/alex/2263/nvt", "rev-parse", "--show-toplevel" }
/home/alex/2263/nvt
[2023-06-12 15:35:52] [git] { "git", "-C", "/home/alex/2263/nvt", "config", "status.showUntrackedFiles" }
[2023-06-12 15:35:52] [git] running job with timeout 400ms
[2023-06-12 15:35:52] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u
M .editorconfig
?? .cgd/HEAD
?? .cgd/config
?? .cgd/description
?? .cgd/hooks/applypatch-msg.sample
?? .cgd/hooks/commit-msg.sample
?? .cgd/hooks/fsmonitor-watchman.sample
?? .cgd/hooks/post-update.sample
?? .cgd/hooks/pre-applypatch.sample
?? .cgd/hooks/pre-commit.sample
?? .cgd/hooks/pre-merge-commit.sample
?? .cgd/hooks/pre-push.sample
?? .cgd/hooks/pre-rebase.sample
?? .cgd/hooks/pre-receive.sample
?? .cgd/hooks/prepare-commit-msg.sample
?? .cgd/hooks/push-to-checkout.sample
?? .cgd/hooks/sendemail-validate.sample
?? .cgd/hooks/update.sample
?? .cgd/index
?? .cgd/info/exclude
?? .cgd/logs/HEAD
?? .cgd/logs/refs/heads/master
?? .cgd/logs/refs/remotes/origin/HEAD
?? .cgd/objects/pack/pack-86c3790f9768d4f5a4503823707e87ab8adfaea4.idx
?? .cgd/objects/pack/pack-86c3790f9768d4f5a4503823707e87ab8adfaea4.pack
?? .cgd/objects/pack/pack-86c3790f9768d4f5a4503823707e87ab8adfaea4.rev
?? .cgd/packed-refs
?? .cgd/refs/heads/master
?? .cgd/refs/remotes/origin/HEAD
!! .cgd/refs/tags/
[2023-06-12 15:35:52] [git] done
[2023-06-12 15:35:52] [git] job success /home/alex/2263/nvt nil
[2023-06-12 15:35:52] [watcher] git start
[2023-06-12 15:35:52] [watcher] Watcher:new '/home/alex/2263/nvt/.cgd' { "FETCH_HEAD", "HEAD", "HEAD.lock", "config", "index" }
[2023-06-12 15:35:52] [watcher] Event:new '/home/alex/2263/nvt/.cgd'
[2023-06-12 15:35:52] [watcher] Event:start '/home/alex/2263/nvt/.cgd'
[2023-06-12 15:35:52] [watcher] Watcher:new '/home/alex/2263/nvt/.cgd' nil
[2023-06-12 15:35:52] [watcher] Watcher:new '/home/alex/2263/nvt/.github' nil
[2023-06-12 15:35:52] [watcher] Event:new '/home/alex/2263/nvt/.github'
[2023-06-12 15:35:52] [watcher] Event:start '/home/alex/2263/nvt/.github'
[2023-06-12 15:35:52] [watcher] Watcher:new '/home/alex/2263/nvt/.hooks' nil
[2023-06-12 15:35:52] [watcher] Event:new '/home/alex/2263/nvt/.hooks'
[2023-06-12 15:35:52] [watcher] Event:start '/home/alex/2263/nvt/.hooks'
[2023-06-12 15:35:52] [watcher] Watcher:new '/home/alex/2263/nvt/doc' nil
[2023-06-12 15:35:52] [watcher] Event:new '/home/alex/2263/nvt/doc'
[2023-06-12 15:35:52] [watcher] Event:start '/home/alex/2263/nvt/doc'
Maybe take a look at #2194 and see if you can pull something from there.
^ rebase on latest |
@alex-courtis you're referring to these two lines?
I'm guessing that second one is created just by the fact that it's a file in the current directory? I suppose we could have it ignore any files that are the value of |
$GIT_DIR
for git changes, if set
@alex-courtis I modified the "is this a git dir?" function for the file ignores to account for I tested it on my machine with various scenarios of |
Thanks for the updates @zhimsel I'll get to review and test this weekend. |
I don't have permission to rebase; I'll leave that to you. There look to be no conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for the following case:
:; export GIT_DIR=~/2263/cgd
:; export GIT_WORK_TREE=~/2263/nvt
:; cd ~/2263
:; mkdir nvt
:; cd nvt
:; echo bar > foo
:; git add foo
:; git commit -a -m "initial commit"
:; git rev-parse --show-toplevel
/home/alex/2263/nvt
:; git rev-parse --git-dir
/home/alex/2263/cgd
$GIT_WORK_TREE
set or unset
$GIT_DIR
set
My git knowledge is insufficient to test cloning an existing repo with non-standard --git-dir
however it should behave in a similar manner.
- Please rebase.
$GIT_DIR
for git changes, if setWhile rarely used, it's possible to set the $GIT_DIR environment variable to instruct git to use a directory other than `.git`. This checks if that environment variable is set; if it is, the plugin will watch that directory. If it's not set, it'll fall back to the default `.git` directory.
This will ignore a path for watching if EITHER it's '.git', or the value of $GIT_DIR (if it's set). If $GIT_DIR is not set, the vim.env object returns `nil`, which will never match `path`.
Done! Sidenote: I renamed the original commit to use
It's as simple as just setting |
Whoops, ignore that closure. I somehow managed to target the "close with comment" button with my keyboard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for pushing this difficult one through.
No problem! Thanks for reviewing and merging. |
About
While rarely used, it's possible to set the $GIT_DIR environment variable to instruct git to use a directory other than
.git
.This checks if that environment variable is set; if it is, the plugin will watch that directory. If it's not set, it'll fall back to the default
.git
directory.Why?
I use a non-standard
.git
folder in my home directory for my dotfiles (~/.git_dotfiles
). If I have$GIT_DIR
set in my env to work on my dotfiles and open up nvim-tree, it'll detect that we're "in a git repo".Prior to this change, it would produce an error that it can't watch the
.git
directory (since it doesn't exist). With this change, it produces no error and correctly watches the$GIT_DIR
directory.Testing
I tested this in my environment by opening up nvim and nvim-tree in various scenarios, ensuring that no errors are produced and git changes are correctly detected (or correctly absent):
$GIT_DIR
unset.git
directory and$GIT_DIR
unset$GIT_DIR
unset$GIT_DIR
set to that directory