Skip to content
Snippets Groups Projects
Commit 94762b13 authored by Jerome Reybert's avatar Jerome Reybert
Browse files

Use --no-prefix to generate diff

It fixes the issue #176 and the PR #177.

PR #177 was almost fine. The idea of the PR was to force src and dst
prefix. The problem was that, to generate patch for new files, we diff
the new file against /dev/null. git does not like prefix for out of
repository files.

The simple fix is to always force --no-prefix. To make it work, git
apply must use -p0 option: this option tells that there is no prefix in
the src dst files paths.
parent e892fb65
Branches
Tags
No related merge requests found
...@@ -102,14 +102,11 @@ function! magit#git#git_dir() ...@@ -102,14 +102,11 @@ function! magit#git#git_dir()
return b:magit_git_dir return b:magit_git_dir
endfunction endfunction
" Use explicit prefixes to avoid issues when the user has configured the
" diff.noprefix option. The actual prefix values are arbitrary and just
" stripped internally by the commands invoking diff / show.
let s:diff_prefix = "--src-prefix a/ --dst-prefix b/"
" magit#git#git_diff: helper function to get diff of a file " magit#git#git_diff: helper function to get diff of a file
" nota: when git fail (due to misformated patch for example), an error " nota: when git fail (due to misformated patch for example), an error
" message is raised. " message is raised.
" WARNING: diff is generated without prefix. To apply this diff, git apply
" must use the option -p0.
" param[in] filemane: it must be quoted if it contains spaces " param[in] filemane: it must be quoted if it contains spaces
" param[in] status: status of the file (see g:magit_git_status_code) " param[in] status: status of the file (see g:magit_git_status_code)
" param[in] mode: can be staged or unstaged " param[in] mode: can be staged or unstaged
...@@ -120,8 +117,7 @@ function! magit#git#git_diff(filename, status, mode) ...@@ -120,8 +117,7 @@ function! magit#git#git_diff(filename, status, mode)
let dev_null = ( a:status == '?' ) ? "/dev/null " : "" let dev_null = ( a:status == '?' ) ? "/dev/null " : ""
let staged_flag = ( a:mode == 'staged' ) ? "--staged" : "" let staged_flag = ( a:mode == 'staged' ) ? "--staged" : ""
let git_cmd=g:magit_git_cmd . " diff --no-ext-diff " . staged_flag . let git_cmd=g:magit_git_cmd . " diff --no-ext-diff " . staged_flag .
\ " " . s:diff_prefix . \ " --no-prefix --no-color -p -U" . b:magit_diff_context .
\ " --no-color -p -U" . b:magit_diff_context .
\ " -- " . dev_null . " " . a:filename \ " -- " . dev_null . " " . a:filename
if ( a:status != '?' ) if ( a:status != '?' )
...@@ -237,7 +233,7 @@ function! magit#git#git_apply(header, selection) ...@@ -237,7 +233,7 @@ function! magit#git#git_apply(header, selection)
if ( selection[-1] !~ '^$' ) if ( selection[-1] !~ '^$' )
let selection += [ '' ] let selection += [ '' ]
endif endif
let git_cmd=g:magit_git_cmd . " apply --recount --no-index --cached -" let git_cmd=g:magit_git_cmd . " apply --recount --no-index --cached -p0 -"
try try
silent let git_result=magit#sys#system(git_cmd, selection) silent let git_result=magit#sys#system(git_cmd, selection)
catch 'shell_error' catch 'shell_error'
...@@ -265,8 +261,8 @@ function! magit#git#git_unapply(header, selection, mode) ...@@ -265,8 +261,8 @@ function! magit#git#git_unapply(header, selection, mode)
endif endif
try try
silent let git_result=magit#sys#system( silent let git_result=magit#sys#system(
\ g:magit_git_cmd . " apply --recount --no-index " . cached_flag . " --reverse - ", \ g:magit_git_cmd . " apply --recount --no-index -p0 --reverse " .
\ selection) \ cached_flag . " - ", selection)
catch 'shell_error' catch 'shell_error'
call magit#sys#print_shell_error() call magit#sys#print_shell_error()
echom "Tried to unaply this" echom "Tried to unaply this"
...@@ -323,8 +319,7 @@ endfunction ...@@ -323,8 +319,7 @@ endfunction
function! magit#git#get_commit_subject(ref) function! magit#git#get_commit_subject(ref)
try try
return magit#utils#strip(magit#sys#system(g:magit_git_cmd . " show " . return magit#utils#strip(magit#sys#system(g:magit_git_cmd . " show " .
\ " " . s:diff_prefix . \" --no-prefix --no-patch --format=\"%s\" " . a:ref))
\" --no-patch --format=\"%s\" " . a:ref))
catch 'shell_error' catch 'shell_error'
return "" return ""
endtry endtry
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment