lambdalisue / vim-gina

👣 Asynchronously control git repositories in Neovim/Vim 8
http://www.vim.org/scripts/script.php?script_id=5531
MIT License
689 stars 27 forks source link

Saving the index in Gina patch fails with "does not exist in index" #259

Closed ptn closed 4 years ago

ptn commented 4 years ago

After a couple of dors and dols, I do :w from the middle buffer, and see this message:

Screen Shot 2020-04-03 at 3 23 18 AM

What's the correct way to complete the patch operation?

lambdalisue commented 4 years ago

What's the correct way to complete the patch operation?

What you did seems correct but I'm not sure while I have no idea what you did in detail.

Could you give me a minimum vimrc and a step by step procedure to reproduce the error on my computer?

a minimum vimrc is something like https://github.com/lambdalisue/fern.vim/issues/83#issuecomment-586678722

ptn commented 4 years ago

I thought this would be a quick question kind of issue, apologies for the incomplete report! Here you go:

Commands I ran in the terminal:

dotfiles - master $ cat ~/.vimrc.min
" How to use this vimrc.min
" vim -u ~/vimrc.min
" nvim -u ~/vimrc.min
if has('vim_starting')
  set nocompatible
endif

" Rewrite it to path/to/your/fern.vim
set runtimepath+=~/code/gina.vim

filetype plugin indent on
syntax on

dotfiles - master $ pwd
/Users/ptorres/code/dotfiles

dotfiles - master $ git status -s -b
## master...origin/master [ahead 4]
 M gitconfig

dotfiles - master $ nvim -u ~/.vimrc.min

Inside nvim:

  1. :e ~/code/dotfiles/gitconfig
  2. :Gina patch
  3. ]c
  4. dor
  5. :w

I got this:

Screen Shot 2020-04-03 at 9 13 12 AM

And same result with vim -u ~/.vimrc.min.

ptn commented 4 years ago

@lambdalisue just noticed something: the git apply command reports it wants to apply /var/folders/.../2, but the error message says that /var/folders/.../1 does not exist. Those numbers are different, and I get that off-by-one difference every single time here.

From the code, those filenames should really be the same, correct?

function! s:apply(git, content) abort
  let tempfile = tempname()
  try
    if writefile(a:content, tempfile) == -1
      return
    endif
    let result = gina#process#call_or_fail(a:git, [
          \ 'apply',
          \ '--verbose',
          \ '--cached',
          \ '--',
          \ tempfile,
          \])
    call gina#core#emitter#emit('command:called:patch')
    return result
  finally
    silent! call delete(tempfile)
  endtry
endfunction

I commented out that finally and saw that it is the file with the greater number that exists.

I tried setting $TMPDIR to /tmp and it didn't help; I still saw the same off-by-one difference though.

ptn commented 4 years ago

Nailed it. s:replace_filenames_in_diff is not replacing anything. This screenshot shows the first line of the diff before and after running all those substitutes in that function:

Screen Shot 2020-04-06 at 20 21 29

I'll see if I can fix it, but I wanted to document the root cause.

ptn commented 4 years ago

The problem was that I had this in my git config: diff.noprefix = true. That setting confuses even git itself: you can't do git diff > patch and then git apply patch with that on (you need to use git apply -p0 patch). It's a popular issue, it seems.

No issues without that setting in git. I think this can be closed then.

lambdalisue commented 4 years ago

I see. Thanks for the information 👍