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

b:gitsigns_head is not updated after checkout -b from Neovim's command line #377

Closed
echasnovski opened this issue Sep 24, 2021 · 1 comment · Fixed by #378
Closed

b:gitsigns_head is not updated after checkout -b from Neovim's command line #377

echasnovski opened this issue Sep 24, 2021 · 1 comment · Fixed by #378
Labels
bug Something isn't working

Comments

@echasnovski
Copy link
Contributor

Description

When branch is checkout with checkout -b from Neovim's command line, b:gitsigns_head does not display the current branch. If checkout is done with checkout, everything works as expected.

Neovim version

NVIM v0.5.0

Operating system and version

Ubuntu 18.04.2

Steps to reproduce

  1. Create git repository and make initial commit.
  2. Create any new file (say, 'file.md').
  3. nvim -nu minimal.lua file.md
  4. Check current value with :echo b:gitsigns_head. This should have the name of default branch.
  5. Run :!git checkout -b feature. This should change branch to feature. Check it with !git branch.
  6. Check again the current value with :echo g:gitsigns_head. This stayed the same.

NOTE: if instead of one command :!git checkout -b feature run two consecutive :!git branch feature and :!git checkout feature, everything works as expected (b:gitsigns_head has value feature).

Expected behavior

Value of b:gistigns_head always shows the name of current HEAD.

Actual behavior

Value of b:gistigns_head not always has the name of current HEAD, as it can have the value HEAD before checkout -b.

Gitsigns debug messages

No response

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'

if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Gitsigns and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end

-- Load plugins
require('packer').startup {
  {
    'wbthomason/packer.nvim',
    {
      'lewis6991/gitsigns.nvim',
      requires = { 'nvim-lua/plenary.nvim' },
    },
    -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
  },
  config = {
    package_root = package_root,
    compile_path = install_path .. '/plugin/packer_compiled.lua',
    display = { non_interactive = true },
  },
}

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

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

  -- ALSO INCLUDE GITSIGNS DEBUG MESSAGES
  vim.cmd('Gitsigns debug_messages')
end

require('packer').sync()

vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
@echasnovski echasnovski added the bug Something isn't working label Sep 24, 2021
@lewis6991
Copy link
Owner

This happens because git checkout -b doesn't modify .git/index.

Solution is to watch a different file.

lewis6991 added a commit that referenced this issue Sep 24, 2021
Some git command likes `git checkout -b` do no update .git/index.
Instead watch the git dir itself to capture all git operations.

Renamed config.watch_index -> config.watch_gitdir

Fixes #377
lewis6991 added a commit that referenced this issue Sep 24, 2021
Some git command likes `git checkout -b` do no update .git/index.
Instead watch the git dir itself to capture all git operations.

Renamed config.watch_index -> config.watch_gitdir

Fixes #377
lewis6991 added a commit that referenced this issue Sep 24, 2021
Some git command likes `git checkout -b` do no update .git/index.
Instead watch the git dir itself to capture all git operations.

Renamed config.watch_index -> config.watch_gitdir

Fixes #377
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
2 participants