lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.93k stars 186 forks source link

nav_hunk with opts { target = 'all' } does not handle files with mixed hunks #1113

Closed iofq closed 3 weeks ago

iofq commented 3 weeks ago

Description

nav_hunk with opts { target = 'all' } does not handle files with mixed staged and unstaged hunks. If you have 4 hunks staged and 2 hunks unstaged, it will only jump between the first 2 hunks in the file, staged or not.

Neovim version

0.10.1

Operating system and version

Nixos 24.05

Expected behavior

Jump between all 6 hunks, staged or not

Actual behavior

Jumped between first 2 hunks in file, one unstaged and one staged

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
} do
  local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.opt.runtimepath:append(install_path)
end

local gs = require("gitsigns")
gs.setup{
  debug_mode = true, -- You must add this to enable debug messages
  on_attach = function ()
    vim.keymap.set('n', ']g', function()
      gs.next_hunk({target = 'all'})
    end)
    vim.keymap.set('n', '[g', function()
      gs.prev_hunk({target = 'all'})
    end)
  end
}

Steps to reproduce

Prereq: setup nvim with above minimal config.

  1. mkdir gitsigns_issue
  2. cd gitsigns_issue
  3. git init
  4. echo "hunk1" >> file
  5. git add file
  6. echo "hunk2" >> file 7 nvim file and observe that ]g and [g don't work between both hunks

Gitsigns debug messages

No response

Gitsigns cache

No response