Skip to content

gitsigns_head shows nil instead of revision #949

@Mikilio

Description

@Mikilio

Description

When using vimdiff I wanted to display the revision of the current buffer on the statusline, however gitsigns_head only shows nil when no inside a branch. It would be nice to instead display a (shortened) commit hash.

Neovim version

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1693350652 system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: " /nix/store/0mrn8874pisnpizlkkvcchkly3dkrhif-neovim-unwrapped-0.9.5/share/nvim "

Operating system and version

NixOS unstable

Expected behavior

Show (shortened) commit hash when in buffer at revision without pointing branch.

Actual behavior

Shows nil instead

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
} 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

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
  -- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
}

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

Steps to reproduce

  1. nvim --clean -u minimal.lua inside git repo
  2. make a change to a file
  3. :Gitsigns diffthis
  4. :lua print(vim.b.gitsigns_head)

Gitsigns debug messages

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions