Skip to content

fix(#1976): improve $GIT_DIR handling #2012

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

Merged
merged 10 commits into from
Apr 22, 2023

Conversation

dmehala
Copy link

@dmehala dmehala commented Feb 19, 2023

  • Retrieve $GIT_DIR using git rev-parse --absolute-git-dir
  • Move $GIT_DIR ignore in the project exploration part

Resolves #1976

- Retrieve $GIT_DIR using `git rev-parse --absolute-git-dir`
- Move $GIT_DIR ignore in the project exploration part

Resolves nvim-tree#1976
@alex-courtis
Copy link
Member

alex-courtis commented Feb 20, 2023

Using a clean room environment with watcher and git logs enabled.

Testing with a default .git setup had issues around identifying the .git directory. Follwing any git status it appears to be treated as a normal directory, with watchers etc. created.

setup

mkdir default
cd default
git init
touch x
git add x
git commit -m "initial commit"

master

open tree
.git is shown
touch x

[2023-02-20 11:04:32] [watcher] event_cb '/home/alex/1976/default' 'x'
[2023-02-20 11:04:32] [watcher] node event scheduled refresh explorer:watch:/home/alex/1976/default:1
[2023-02-20 11:04:32] [watcher] node event executing refresh '/home/alex/1976/default'
[2023-02-20 11:04:32] [git] running job with timeout 400ms
[2023-02-20 11:04:32] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u /home/alex/1976/default
[2023-02-20 11:04:32] [git] job success    /home/alex/1976/default /home/alex/1976/default

touch .git/config

[2023-02-20 11:04:52] [watcher] event_cb '/home/alex/1976/default/.git' 'config'
[2023-02-20 11:04:52] [watcher] git event scheduled '/home/alex/1976/default'
[2023-02-20 11:04:52] [watcher] git event executing '/home/alex/1976/default'
[2023-02-20 11:04:52] [git] running job with timeout 400ms
[2023-02-20 11:04:52] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u
[2023-02-20 11:04:52] [git] job success    /home/alex/1976/default nil

branch

open tree
.git is not shown
touch x

[2023-02-20 11:05:29] [watcher] event_cb '/home/alex/1976/default' 'x'
[2023-02-20 11:05:29] [watcher] node event scheduled refresh explorer:watch:/home/alex/1976/default:1
[2023-02-20 11:05:29] [watcher] node event executing refresh '/home/alex/1976/default'
[2023-02-20 11:05:29] [git] running job with timeout 400ms
[2023-02-20 11:05:29] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u /home/alex/1976/default
[2023-02-20 11:05:29] [git] job success    /home/alex/1976/default /home/alex/1976/default
[2023-02-20 11:05:29] [watcher] Watcher:new '/home/alex/1976/default/.git' nil

.git is now shown
touch .git/config

[2023-02-20 11:06:00] [watcher] event_cb '/home/alex/1976/default/.git' 'config'
[2023-02-20 11:06:00] [watcher] git event scheduled '/home/alex/1976/default'
[2023-02-20 11:06:00] [watcher] node event scheduled refresh explorer:watch:/home/alex/1976/default/.git:4
[2023-02-20 11:06:00] [watcher] git event executing '/home/alex/1976/default'
[2023-02-20 11:06:00] [git] running job with timeout 400ms
[2023-02-20 11:06:00] [git] git --no-optional-locks status --porcelain=v1 -z --ignored=matching -u
[2023-02-20 11:06:00] [watcher] node event executing refresh '/home/alex/1976/default/.git'
[2023-02-20 11:06:00] [git] { "git", "-C", "/home/alex/1976/default/.git", "rev-parse", "--show-toplevel" }
fatal: this operation must be run in a work tree
[2023-02-20 11:06:00] [watcher] Watcher:new '/home/alex/1976/default/.git/branches' nil
[2023-02-20 11:06:00] [watcher] Event:new '/home/alex/1976/default/.git/branches'
[2023-02-20 11:06:00] [watcher] Event:start '/home/alex/1976/default/.git/branches'
[2023-02-20 11:06:00] [watcher] Watcher:new '/home/alex/1976/default/.git/hooks' nil
[2023-02-20 11:06:00] [watcher] Event:new '/home/alex/1976/default/.git/hooks'
[2023-02-20 11:06:00] [watcher] Event:start '/home/alex/1976/default/.git/hooks'
[2023-02-20 11:06:00] [watcher] Watcher:new '/home/alex/1976/default/.git/info' nil
[2023-02-20 11:06:00] [watcher] Event:new '/home/alex/1976/default/.git/info'
[2023-02-20 11:06:00] [watcher] Event:start '/home/alex/1976/default/.git/info'
[2023-02-20 11:06:00] [watcher] Watcher:new '/home/alex/1976/default/.git/logs' nil
[2023-02-20 11:06:00] [watcher] Event:new '/home/alex/1976/default/.git/logs'
[2023-02-20 11:06:00] [watcher] Event:start '/home/alex/1976/default/.git/logs'
[2023-02-20 11:06:00] [watcher] Watcher:new '/home/alex/1976/default/.git/objects' nil
[2023-02-20 11:06:00] [watcher] Event:new '/home/alex/1976/default/.git/objects'
[2023-02-20 11:06:00] [watcher] Event:start '/home/alex/1976/default/.git/objects'
[2023-02-20 11:06:00] [watcher] Watcher:new '/home/alex/1976/default/.git/refs' nil
[2023-02-20 11:06:00] [watcher] Event:new '/home/alex/1976/default/.git/refs'
[2023-02-20 11:06:00] [watcher] Event:start '/home/alex/1976/default/.git/refs'
[2023-02-20 11:06:00] [git] job success    /home/alex/1976/default nil

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Looking good so far.

Initial testing shows things are mostly working for a default .git directory and a user specified one.

Please:

@dmehala
Copy link
Author

dmehala commented Feb 26, 2023

Thanks for your feedback @alex-courtis. I hope I will have time today or tomorrow to improve the PR.

- move norm_path to utils.lua
- fix comment nvim-tree#2012
@dmehala
Copy link
Author

dmehala commented Mar 4, 2023

I think I've fixed #2012 comment. However, I was not able to test on cygwin and WSL, to be honest, I just reused code already written.

@alex-courtis
Copy link
Member

alex-courtis commented Mar 5, 2023

I think I've fixed #2012 comment. However, I was not able to test on cygwin and WSL, to be honest, I just reused code already written.

Ah, damn. I assumed you were using windows.

Do you have a windows environment you can test with?

The code looks the same, however I am nervous...

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

This appears to work for default and different git dirs. I'll fully test once we sort out the watcher ignores.

Please:

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

@alex-courtis
Copy link
Member

Any updates on this one @dmehala ?

@dmehala
Copy link
Author

dmehala commented Apr 12, 2023

Hey @alex-courtis,

Sorry for the late reply, I think I've manage to follow your requirements in 5a83629. May you have a look? :)

@alex-courtis
Copy link
Member

Experimental async git status handling has been added #2104

Please do test this.

I am dogfooding this branch, with async enabled for ~week.

@gegoune
Copy link
Collaborator

gegoune commented Apr 15, 2023

I have been using it for a while, didn't notice any issues.


EDIT: meant #2104 - async git, to be clear.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Many thanks for your contribution @dmehala !

@alex-courtis alex-courtis merged commit 517dee6 into nvim-tree:master Apr 22, 2023
hinell pushed a commit to hinell/nvim-tree.lua that referenced this pull request Apr 22, 2023
* Improve $GIT_DIR handling

- Retrieve $GIT_DIR using `git rev-parse --absolute-git-dir`
- Move $GIT_DIR ignore in the project exploration part

Resolves nvim-tree#1976

* Code review

- move norm_path to utils.lua
- fix comment nvim-tree#2012

* add comments for utils.norm_path

* get_git_directory use norm_path from utils

* watcher improvements

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
alex-courtis added a commit that referenced this pull request Apr 29, 2023
dmehala pushed a commit to dmehala/nvim-tree.lua that referenced this pull request May 7, 2023
* Improve $GIT_DIR handling

- Retrieve $GIT_DIR using `git rev-parse --absolute-git-dir`
- Move $GIT_DIR ignore in the project exploration part

Resolves nvim-tree#1976

* Code review

- move norm_path to utils.lua
- fix comment nvim-tree#2012

* add comments for utils.norm_path

* get_git_directory use norm_path from utils

* watcher improvements

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
@alex-courtis alex-courtis mentioned this pull request Jun 11, 2023
4 tasks
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.

File system watcher throws error when opening git repo with $GIT_DIR set
3 participants