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

Manual :Gitsigns attach does not work if attach_to_untracked = false #1026

Open
przepompownia opened this issue May 28, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@przepompownia
Copy link

Description

For reporting previous issues I tested Gitsigns without attach_to_untracked (false by default since some moment) and found that I cannot manually attach new untracked file.

Neovim version

v0.11.0-dev-124+g90a4b1a59

Operating system and version

Debian Sid

Expected behavior

:Gitsigns attach works independently of attach_to_untracked.

Actual behavior

:Gitsigns attach seems to not work.

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

Inside some Git repo

  1. nvim --clean -u minimal.lua new3
  2. Gitsigns attach
  3. :Gistigns stage_buffer
  4. quit or suspend nvim
  5. GIT_PAGER= git diff --staged -- new3

Gitsigns debug messages

attach(1): Attaching (trigger=BufNewFile)
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name
run_job: git --version
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir .../.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol .../new3
attach(1): Not a file
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
cli.run: Running action 'attach' with arguments { "%" }
attach(%): Attaching
cli.run: Running action 'attach' with arguments { 1 }
attach(1): Attaching
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir .../.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol .../new3
@przepompownia przepompownia added the bug Something isn't working label May 28, 2024
@lewis6991
Copy link
Owner

lewis6991 commented May 28, 2024

This is because the logic that attach_to_untracked drives attach():

  if not config.attach_to_untracked and git_obj.object_name == nil then
    dprint('File is untracked')
    return
  end

attach() does a lot of checks to make sure the buffer is attachable. I'm not how else to implement this so attach() ignores only some of these checks.

@przepompownia
Copy link
Author

I'm not encouraging you to make any bigger effort here, especially that this issue is only a side effect of working on a minimal reproduction environment. I have set attach_to_untracked to true in my real environment.

@lewis6991
Copy link
Owner

lewis6991 commented May 28, 2024

FWIW I think it would be nice if it worked. If a user has attach_to_untracked = false, :Gitsigns attach provides a convenient way to stage an untracked buffer.

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