aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorJean-Sebastien Trottier <jst@qualipsoft.com>2024-07-22 04:06:19 -0400
committerChristian Clason <c.clason@uni-graz.at>2024-07-22 13:11:11 +0200
commitdebf5816eee21b7d51025ef17ba0647386226cb5 (patch)
treef768c668676903aa79003974802fae7762fb239b /lua
parentfix(idl): fix break changes (diff)
downloadnvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.tar
nvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.tar.gz
nvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.tar.bz2
nvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.tar.lz
nvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.tar.xz
nvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.tar.zst
nvim-treesitter-debf5816eee21b7d51025ef17ba0647386226cb5.zip
fix(install): abort installation using git in active git session
Problem: Installing a parser using git in an active git session (e.g., when editing a commit message) can corrupt the corresponding repository. Solution: Check for typical environment variables first and abort installation if found.
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/shell_command_selectors.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/shell_command_selectors.lua b/lua/nvim-treesitter/shell_command_selectors.lua
index 9622f5801..f95c84ae8 100644
--- a/lua/nvim-treesitter/shell_command_selectors.lua
+++ b/lua/nvim-treesitter/shell_command_selectors.lua
@@ -289,6 +289,31 @@ function M.select_download_commands(repo, project_name, cache_folder, revision,
local git_folder = utils.join_path(cache_folder, project_name)
local clone_error = "Error during download, please verify your internet connection"
+ -- 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 environemnt variables and abort if found.
+ for _, k in pairs {
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
+ "GIT_CEILING_DIRECTORIES",
+ "GIT_DIR",
+ "GIT_INDEX",
+ "GIT_INDEX_FILE",
+ "GIT_OBJECT_DIRECTORY",
+ "GIT_PREFIX",
+ "GIT_WORK_TREE",
+ } do
+ if vim.uv.os_getenv(k) then
+ vim.api.nvim_err_writeln(
+ string.format(
+ "Cannot install %s with git in an active git session. Exit the session and run ':TSInstall %s' manually",
+ project_name
+ )
+ )
+ return {}
+ end
+ end
+
return {
{
cmd = "git",