-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refusing to install while embedded in a git session #6959
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
|
Duplicate of #6745. The actual resolution is deprecating |
|
(Although this is a cleaner fix than the closed PR.) |
| "GIT_PREFIX", | ||
| "GIT_WORK_TREE", | ||
| }) do | ||
| if luv.os_getenv(k) then |
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.
| if luv.os_getenv(k) then | |
| if vim.uv.os_getenv(k) then |
| -- Git repository. | ||
| -- The check below will refuse to perform any risky action until a safe way | ||
| -- is implemented. | ||
| local luv = vim.loop |
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.
| local luv = vim.loop |
| -- Running `git clone` or `git checkout` while running under Git (such as | ||
| -- editing a `git commit` message) will likely fail to install parsers | ||
| -- (such as 'gitcommit') and can also corrupt the index file of the current | ||
| -- Git repository. | ||
| -- The check below will refuse to perform any risky action until a safe way | ||
| -- is implemented. |
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.
| -- Running `git clone` or `git checkout` while running under Git (such as | |
| -- editing a `git commit` message) will likely fail to install parsers | |
| -- (such as 'gitcommit') and can also corrupt the index file of the current | |
| -- Git repository. | |
| -- The check below will refuse to perform any risky action until a safe way | |
| -- is implemented. | |
| -- Running `git clone` or `git checkout` while running under Git (such as | |
| -- editing a `git commit` message) will likely fail to install parsers | |
| -- (such as 'gitcommit') and can also corrupt the index file of the current | |
| -- Git repository. Check for typical Git environment variables and abort. |
| "GIT_WORK_TREE", | ||
| }) do | ||
| if luv.os_getenv(k) then | ||
| return vim.api.nvim_err_writeln("Refusing to install while embedded in a git session. Run ':TSInstall " .. project_name .. "' manually") |
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.
Please run stylua (from the repository root) on this file.
|
(and please allow maintainers to push to your PR; you should always open PRs from your personal fork, not some other org.) |
|
superseded by #6960 |
If the
GIT_DIRenvironment variable is set, then runninggit checkoutcan fail to install plugins but also corupt the Git repositoryGIT_DIRis pointing to.Here's a script to reproduce the issue.
Save the above as "repro.sh", for example, and run it.
It creates a minimal Neovim configuration and an empty git repo. While doing a fake git commit, Treesitter will fail to install the
gitcommitparser with the following message:It can also corrupt the repo that
GIT_DIRis pointing to, e.g.:This PR attempts to mitigate the issue by flat out refusing to install parsers while running within a Git session. The list of Git environments being used for detection is very broad: In my testing, setting GIT_DIR see ms to be a prerequisite to cause the issue but just unsetting it within Treesitter is not enough (although parser can install successfully) as it causes Git to set other variables such as GIT_INDEX_FILE and I suspect t hat may be the one doing the damage (corruption of the git repository).