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: libgit2 error on opening <cmd>Fugit2<cr> #48

Closed
3 tasks done
zan-preston opened this issue May 8, 2024 · 14 comments
Closed
3 tasks done

bug: libgit2 error on opening <cmd>Fugit2<cr> #48

zan-preston opened this issue May 8, 2024 · 14 comments
Labels
bug Something isn't working

Comments

@zan-preston
Copy link

Did you check docs and existing issues?

  • I have read all the plugin docs
  • I have searched the existing issues
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.9.5

Operating system/version

MacOS 14.4.1

Describe the bug

When opening fugit with my keybind that maps to <cmd>Fugit2<cr>, I hit an error that ends up coming from libgit2.

   Error  08:55:11 msg_show.lua_error Error executing Lua callback: ...are/nvim/lazy/fugit2.nvim/lua/fugit2/view/git_status.lua:143: [Fugit2] libgit2 Error -1
stack traceback:
	[C]: in function 'error'
	...are/nvim/lazy/fugit2.nvim/lua/fugit2/view/git_status.lua:143: in function 'init'
	.../.local/share/nvim/lazy/nui.nvim/lua/nui/object/init.lua:132: in function 'GitStatus'
	...local/share/nvim/lazy/fugit2.nvim/lua/fugit2/view/ui.lua:23: in function 'new_fugit2_status_window'
	...n/.local/share/nvim/lazy/fugit2.nvim/lua/fugit2/init.lua:82: in function <...n/.local/share/nvim/lazy/fugit2.nvim/lua/fugit2/init.lua:78>

The documentation for libgit2 states this is just a "Generic Git Error".

Below is my plugin config (lazy)

return {
  {
    "SuperBo/fugit2.nvim",
    opts = {
      libgit2_path = "/opt/homebrew/lib/libgit2.dylib",
      width = 70,
    },
    dependencies = {
      "MunifTanjim/nui.nvim",
      "nvim-tree/nvim-web-devicons",
      "nvim-lua/plenary.nvim",
      {
        "chrisgrieser/nvim-tinygit", -- optional: for Github PR view
        dependencies = { "stevearc/dressing.nvim" },
      },
    },
    cmd = { "Fugit2", "Fugit2Graph" },
    keys = {
      { "<leader>gF", "<cmd>Fugit2<cr>", desc = "Fugit2" },
    },
  },
  {
    -- optional: for diffview.nvim integration
    "sindrets/diffview.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    -- lazy, only load diffview by these commands
    cmd = {
      "DiffviewFileHistory",
      "DiffviewOpen",
      "DiffviewToggleFiles",
      "DiffviewFocusFiles",
      "DiffviewRefresh",
    },
  },
}

I've attempted reinstalling libgit2, no luck.

Other things of note:

  1. If I'm not in a git repository and I attempt to open fugit, I get an expected an appropriately handled error that I'm not in a git repo.
  2. If I cd into /opt/homebrew/lib/ (which is a git repo), I CAN invoke fugit WITHOUT ERROR.
  3. brew doctor reports no errors.
  4. running the following exports has no effect
    export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"
    export LD_LIBRARY_PATH="$(brew --prefix)/lib${LD_LIBRARY_PATH:+:"${LD_LIBRARY_PATH}"}"
    export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$(brew --prefix)/lib"
    

Steps To Reproduce

  1. install libgit2 via homebrew on MacOS 14.4.1
  2. Install neovim 0.9.5
  3. set up lazy.nvim package manager
  4. Use the above lazy.nvim config for fugit2
  5. Invoke fugit with either the keybind defined above or <cmd>Fugit2<cr>

Expected Behavior

Fugit2 invokes without error.

@zan-preston zan-preston added the bug Something isn't working label May 8, 2024
@SuperBo
Copy link
Owner

SuperBo commented May 8, 2024

This error should be specific to git repo. Could you share with me your git repo state by running git status. Or you can show me how to re-create your local git repo.

@zan-preston
Copy link
Author

Here's just an example in my neovim config

nvim git:main ❯ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   lazy-lock.json
        modified:   lua/plugins/colorscheme.lua
        modified:   lua/plugins/fugit2.lua
        modified:   lua/plugins/obsidian.lua

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        spell/

On another repo that's clean

dot git:main ❯ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

The error occurs in both repos (and in any repo I've tested)

@SuperBo
Copy link
Owner

SuperBo commented May 8, 2024

If there are no private things in those repos, could you help me zip them (including ".git" folder) and send it here. This error happens when libgit2 can't get index for corresponding repo, I need your files to do more investigation :D

@zan-preston
Copy link
Author

dot.tgz
nvim.tgz
Here you go! These two are public that I can share. Unfortunately, can't share any of my work repos.

@SuperBo
Copy link
Owner

SuperBo commented May 8, 2024

Weird, it can open normally on my machine,

Screenshot 2024-05-08 at 23 54 02

Can you do the following steps:

  • open one file in repo by neovim nvim stylua.toml
  • Then trigger command :Fugit2
  • Trigger command :Fugit2Graph

@zan-preston
Copy link
Author

When calling :Fugit2 I get the same error/stack trace.

I am, however, able to open :Fugit2Graph

@SuperBo
Copy link
Owner

SuperBo commented May 8, 2024

@zan-preston, can you try with :Fugit2Diff, still can't know why this bug happens T_T

@zan-preston
Copy link
Author

Same error with :Fugit2Diff

@SuperBo
Copy link
Owner

SuperBo commented May 8, 2024

@zan-preston, can you wait till tomorrow, I will implement new mechanism to get more meaningful error message from libgit2. For now, -1 error code doesn't show the real error root.

@zan-preston
Copy link
Author

Yep! Sure thing. I really appreciate all the help. It's certainly seeming like a weird corner case

@zan-preston
Copy link
Author

I believe I've discovered the issue. To deal with some performance issues on some very large repos we have at $work, I had enabled feature.manyFiles = true in my global .gitconfig which is incompatible with libgit2 until the recent 1.8.0 release (which I don't have yet).

https://stackoverflow.com/questions/76749908/what-are-the-negative-consequences-of-setting-feature-manyfiles-for-small-to-m

@SuperBo
Copy link
Owner

SuperBo commented May 9, 2024

Thank you @zan-preston, to tackle this, you can turn off manyFiles for small repo, or set feature.manyFiles = true per repo (not globally). Or you can build libgit2 1.8 on your own.

It's time to create Wiki and add FAQ section :D.

Homebrew update are still in progress Homebrew/homebrew-core#166767

@zan-preston
Copy link
Author

That's exactly what I did 😄. A potential tip, for the eventual wiki. If you want to fix your existing cloned repo after the fact of changing this config value, you might need to delete your .git/index file and then run git status or something to have git regenerate it. But I haven't investigated the potential ramifications of that to your reflog or anything else for unintended consequences.

Also, if users aren't comfortable with manipulating their .git folder within a repository manually, then a fresh clone of the repository might be needed for them.

Also, I would say you could close this bug if you'd like now since it wasn't actually a bug related to fugit2, but an incompatibility with libgit2 and my personal global config.

@SuperBo
Copy link
Owner

SuperBo commented May 14, 2024

Thank you @zan-preston , the wiki is up https://github.com/SuperBo/fugit2.nvim/wiki

@SuperBo SuperBo closed this as completed May 14, 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
Projects
None yet
Development

No branches or pull requests

2 participants