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

bug: lazy unset GIT_DIR and GIT_WORK_TREE environment variables #1735

Open
4 tasks done
luigir-it opened this issue Sep 3, 2024 · 3 comments
Open
4 tasks done

bug: lazy unset GIT_DIR and GIT_WORK_TREE environment variables #1735

luigir-it opened this issue Sep 3, 2024 · 3 comments
Labels
bug Something isn't working stale

Comments

@luigir-it
Copy link

luigir-it commented Sep 3, 2024

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.10.1

Operating system/version

Linux

Describe the bug

Since this commit lazy.nvim unsets GIT_DIR. This was done to not interfere with its internal use of git, as stated in #434. Few months later, this unset GIT_WORK_TREE.

While this is a sane default behavior, it breaks my workflow. I, just like the user of #434, use those variables to manage my dotfiles, but use nvim to edit them, and plugins like gitsigns or the one used to blame lines need those variables to be set.

Adding a way to alter this behavior would be appreciated. For example, right now I'm using this hack:

~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/process.lua
131,132c131,134
<   env.GIT_DIR = nil
<   env.GIT_WORK_TREE = nil
---
>   if not env.DISISDOT then
>     env.GIT_DIR = nil
>     env.GIT_WORK_TREE = nil
>   end

So if I set DISISDOT set to true, lazy.nvim would not overwrite the other two variables.


If the suggested change is not implemented, this is the workaround I've been using for few weeks and works just fine.
Patch ~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/process.lua with dots_patch.txt using patch -bf ~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/process.lua -i /path/to/dots_patch.txt
Remember that lazy.nvim will complain about tampering it's code when updating itself. So you should reverse the patch when applying an update.

If you want to automate the entire process, edit ~/.config/nvim/lua/config/autocmd.lua and add the following autocommands

  1. This will set DISISDOT to true if working with a dotfile
vim.api.nvim_create_autocmd({ "BufReadPost" }, {
  pattern = { "*" },
  callback = function()
    local file = vim.api.nvim_buf_get_name(0)
    if
      os.execute(
        "/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME ls-files --error-unmatch "
          .. file
          .. " >/dev/null 2>&1"
      ) == 0
    then
      -- $DISISDOT will signal lazy.nvim to not overwrite $GIT_DIR and $GIT_WORK_TREE
      -- REMEMBER that this works because you changed the behaviour of ~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/process.lua
      vim.env.DISISDOT = true
      vim.env.GIT_DIR = vim.env.HOME .. "/.dotfiles/"
      vim.env.GIT_WORK_TREE = vim.env.HOME
    end
  end,
})
  1. This will deal with lazy.nvim updates
vim.api.nvim_create_autocmd({ "User" }, {
  pattern = { "LazyUpdatePre" },
  callback = function()
    os.execute(
      "patch -bfR ~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/process.lua -i ~/dots_patch.txt"
    )
  end,
})
vim.api.nvim_create_autocmd({ "User" }, {
  pattern = { "LazyUpdate" },
  callback = function()
    os.execute(
      "patch -bf ~/.local/share/nvim/lazy/lazy.nvim/lua/lazy/manage/process.lua -i ~/dots_patch.txt"
    )
    print("Patched!")
  end,
})

Steps To Reproduce

  1. set GIT_DIR and GIT_WORK_TREE
  2. use a plugin that use those variables

Expected Behavior

The variable should be unset by default, but the user should have the possibility to set them.

@luigir-it luigir-it added the bug Something isn't working label Sep 3, 2024
@folke
Copy link
Owner

folke commented Sep 16, 2024

I don't really understand your use-case.
You can still set those variables in your env and they would be used by those plugins.

The lines you are referring to, just don't use those env vars for lazy specifically.

What's the problem you're trying to solve here?

@luigir-it
Copy link
Author

luigir-it commented Sep 29, 2024

I'm sorry I didn't explain the issue properly.
The plugins will use those env indeed.
The issue persist only for 'Git Blame Line' (space+g+b) and similar options.

This is probably because 'Git Blame Line' uses float_cmd from lazy.util
and when spawning the floating terminal, lazy unset those git related env vars

This will prompt an error:

git -C . log -n 3 -u -L 99,+1:/home/pcino/dotfiles.conf`

## Error
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

That prevents me from using 'Git Blame Line'

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants