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

New buffer created from saveas is attached to the old file #1021

Closed
przepompownia opened this issue May 25, 2024 · 4 comments · Fixed by #1024 or #1011
Closed

New buffer created from saveas is attached to the old file #1021

przepompownia opened this issue May 25, 2024 · 4 comments · Fixed by #1024 or #1011
Labels
bug Something isn't working

Comments

@przepompownia
Copy link

Description

Nothing more than in the title.

Neovim version

v0.11.0-dev-76+g8db9a0e5a

Operating system and version

Debian Sid

Expected behavior

No response

Actual behavior

Using gitsigns on the new file affects (only) the old one.

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. Prepare some already versioned oldfile
  2. nvim --clean -u minimal.luaoldfile`
  3. execute :saveas newfile inside
  4. add some changes to newfile
  5. run :Gitsigns stage_buffer there
  6. quit Neovim and see output from git diff and git diff --cached. For me only oldfile is shown.

Gitsigns debug messages

(from attach):

attach(1): Attaching (trigger=setup)
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name
run_job: git --version
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 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 .../2024-05-24-14.03.21-gitsigns-saveas/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol .../2024-05-24-14.03.21-gitsigns-saveas/oldfile
watch_gitdir(1): Watching git dir
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir .../2024-05-24-14.03.21-gitsigns-saveas/.git show e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
cli.run: Running action 'debug_messages' with arguments {}
cli.run: Running action 'debug_messages' with arguments {}
attach(1): Already attached
cli.run: Running action 'stage_buffer' with arguments {}
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir .../2024-05-24-14.03.21-gitsigns-saveas/.git apply --whitespace=nowarn --cached --unidiff-zero -
watcher_cb(1): Git dir update: 'index.lock' { rename = true } (ignoring)
watcher_cb(1): Git dir update: 'index.lock' { change = true } (ignoring)
watcher_cb(1): Git dir update: 'index.lock' { rename = true } (ignoring)
watcher_cb(1): Git dir update: 'index' { rename = true }
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir .../2024-05-24-14.03.21-gitsigns-saveas/.git show e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
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 .../2024-05-24-14.03.21-gitsigns-saveas/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol .../2024-05-24-14.03.21-gitsigns-saveas/oldfile
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir .../2024-05-24-14.03.21-gitsigns-saveas/.git show 1a09f84cdecb5aec927ac553af7161376c35465f
cli.run: Running action 'debug_messages' with arguments {}
@lewis6991
Copy link
Owner

@przepompownia can you test #1024. I've changed the behaviour so the buffer is detached on :saveas. If attached_to_untracked is enabled, it will then re-attach.

@przepompownia
Copy link
Author

Thank you, autocommands from #1024 fix this issue (I have checked it with attach_to_untracked too). attached_to_untracked exists only in CHANGELOG.

As a side effect I found that staging such empty buffer results with still left unstaged deletion of an empty line. I'm not sure if it's a bug to report in a separate issue.

@lewis6991
Copy link
Owner

As a side effect I found that staging such empty buffer results with still left unstaged deletion of an empty line. I'm not sure if it's a bug to report in a separate issue.

Sounds weird. Probably worth raising.

@przepompownia
Copy link
Author

Sounds weird. Probably worth raising.

#1025

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