NeogitOrg / NeogitOrg/neogit

staging is not 100% robust

Open
#256 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Lua
Stars
5.6k
Forks
357
Avg merge
15h 47m
Merged PRs (30d)
2

Description

Description

It's a bit of an unusual use-case, but I've been tracking diffs in source control, and staging them bit by bit. This works fine in emacs magit, but I think neogit's hunk parsing is getting confused by the hunks in the git operation itself and the hunks in the diff that we are source controlling and which are unrelated.

Neovim version

NVIM v0.5.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

fedora 34

Steps to reproduce

first version, s.diff

diff --git a/lua/neogit/buffers/common.lua b/lua/neogit/buffers/common.lua
index 504ed37..cfa8a2d 100644
--- a/lua/neogit/buffers/common.lua
+++ b/lua/neogit/buffers/common.lua
@@ -22,6 +22,7 @@ M.Diff = Component.new(function(diff)
     local content = map(range(hunk.diff_from + 1, hunk.diff_to), function(i)
       return diff.lines[i]
     end)
+    -- test
 
     return {
       header = header,

second version, s2.diff

diff --git a/lua/neogit/buffers/common.lua b/lua/neogit/buffers/common.lua
index 504ed37..96bc74f 100644
--- a/lua/neogit/buffers/common.lua
+++ b/lua/neogit/buffers/common.lua
@@ -10,6 +10,7 @@ local filter = util.filter
 local intersperse = util.intersperse
 local range = util.range
 
+-- test3
 local M = {}
 
 local diff_add_matcher = vim.regex('^+')
@@ -31,6 +32,7 @@ M.Diff = Component.new(function(diff)
 
   return col.tag("Diff") {
     text(diff.kind .. " " .. diff.file),
+    -- test2
     col.tag("HunkList")(map(hunk_props, M.Hunk))
   }
 end)

We want to track these files in source control.

If you save both these files on disk, as /tmp/s.diff and /tmp/s2.diff, then do...

git init
cp /tmp/s.diff s.diff
git add s.diff
git commit -m "first version"
cp /tmp/s2.diff s.diff
nvim -nu minimal.lua
:Neogit

Then in neogit go over Unstaged changes->Modified s.diff, press tab, go over the line that says "--- add/lua/neogit..." then press s to stage the hunk.

Expected behavior

The hunk gets staged.
Doing the same thing in magit in emacs stages without problem.

Actual behavior

Neogit displays Git error (128).

Minimal config
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      {
        "TimUntersberger/neogit",
        requires = {
          { "nvim-lua/plenary.nvim" },
          { "sindrets/diffview.nvim" },
        },
        config = function()
          print("loaded neogit")
          require("neogit").setup()
        end,
      },
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  })
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing neogit and dependencies.")
  vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the s.diff and s2.diff fixtures and the minimal.lua configuration, then inspect Neogit's hunk parsing and staging path. Verify the behavior through the described Neogit flow: staging the hunk in the modified s.diff file should succeed without Git error (128).

Written by the indexing model from the issue text.

Assessment

Tech stack
git, lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.