1

I have done a git-diff to generate a patch file:

cd
git diff --no-prefix ~/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim  ~/compiler.vim > ~/vimlatex.patch

The resulting patch is

diff --git home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim home/rudra/compiler.vim
index 65cd33a..abfcff7 100644
--- home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
+++ home/rudra/compiler.vim
@@ -434,7 +434,8 @@ function! Tex_ForwardSearchLaTeX()
        else
            " We must be using a generic UNIX viewer
            " syntax is: viewer TARGET_FILE LINE_NUMBER SOURCE_FILE
-
+           let mainfnameRelative = fnameescape(fnamemodify(Tex_GetMainFileName(), ':p:.:r'))
+           let target_file = mainfnameRelative . "." . s:target
            let execString .= join([viewer, target_file, linenr, sourcefile])

        endif

I want to apply this patch to /home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim

But when I am trying to apply the patch, its giving:

patch -p0 < vimlatex.patch 
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim home/rudra/compiler.vim
|index 65cd33a..abfcff7 100644
|--- home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
|+++ home/rudra/compiler.vim
--------------------------
File to patch: /home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
patching file /home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim

The problem is, while it is working fine, I want it to understand which file it should patch, without asking me File to patch:

How I can achieve this?

2
  • 1
    Note how your patch is missing the starting /. So in order to apply the patch you need to be located in the root directory, or to supplement the appropriate prefix truncation count with -p.
    – undercat
    Commented Apr 28, 2017 at 3:48
  • Thanks, but I am not sure why the / is missing.
    – BaRud
    Commented Apr 28, 2017 at 7:30

1 Answer 1

3

By default, patch strips paths from the target files, so you can apply your patch using

patch < vimlatex.patch

(assuming there’s a compiler.vim file in the current directory).

Specifying -p0 instructs it to use all the target path, so it expects to find a file called home/rudra/compiler.vim starting from the current directory. The explanation for that is that the command you used to create the patch was transformed before diff is run; the command really used to create the patch is recorded as the first line of the patch (basically, ~ becomes /home/rudra, and the leading / is stripped):

diff --git home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim home/rudra/compiler.vim

As a result, patch -p0 by default expects to find a file matching home/rudra/compiler.vim (the target file) as explained above.

I don’t think there’s a reliable way to produce the kind of patch you’re after, because patch explicitly ignores absolute paths. I’d recommend just using plain diff with relative paths:

cd
diff -u .vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim  compiler.vim > vimlatex.patch

and applying the patch in the appropriate directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .