junkblocker / patchreview-vim

Vim/Neovim plugin for doing single, multi-patch or diff code reviews
http://www.vim.org/scripts/script.php?script_id=1563
108 stars 8 forks source link

Didn't detect new file correctly #6

Closed Mizuchi closed 9 months ago

Mizuchi commented 9 years ago

It looks like patchreview-vim didn't handle new files in diff correctly. Here is an example to reproduce this issue

[ytj@localhost ~]$ mkdir repo
[ytj@localhost ~]$ cd repo
[ytj@localhost repo]$ git init
Initialized empty Git repository in /home/ytj/repo/.git/
[ytj@localhost repo]$ echo whatever > a
[ytj@localhost repo]$ git add a
[ytj@localhost repo]$ git commit -m "first"
[master (root-commit) 2be937f] first
 1 file changed, 1 insertion(+)
 create mode 100644 a
[ytj@localhost repo]$ echo hello > README
[ytj@localhost repo]$ git add README
[ytj@localhost repo]$ git commit -m "add readme"
[master 8245157] add readme
 1 file changed, 1 insertion(+)
 create mode 100644 README
[ytj@localhost repo]$ git diff HEAD^
diff --git a/README b/README
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+hello
[ytj@localhost repo]$ vim -c "DiffReview git diff HEAD^"

Basically it simply added a new file in the last commit. When I was "DiffReview git diff HEAD^" to review the diff for the last commit, I got such error:

Source directory: /home/ytj/repo
------------------
ERROR: Original file b/README does not exist.
New file        :  b/README
-----
Done.
junkblocker commented 9 years ago

It seems that I am not processing strip levels (e.g. 1 here for b/ prefix) for patches doing file additions or removals. I'll need to revisit my code to see why I did that before I relax that restriction. This might take a while as I am currently traveling. Meanwhile you can apply this patch and see if it doesn't break other things for you.

diff --git a/autoload/patchreview.vim b/autoload/patchreview.vim
index dd19fa9..3623ee5 100644
--- a/autoload/patchreview.vim
+++ b/autoload/patchreview.vim
@@ -673,9 +673,9 @@ function! patchreview#extract_diffs(lines, default_strip_count)            "{{{
         let g:patches['patch'] += [l:this_patch]
         unlet! l:this_patch
         call s:me.progress('Collected  ' . l:filepath)
-        if l:p_type == '!'
+        "if l:p_type == '!'
           call s:guess_prefix_strip_value(l:filepath, a:default_strip_count)
-        endif
+        "endif
         let l:line_num -= 1
         call s:state('START')
         continue
Mizuchi commented 9 years ago

Your patch works for me. Thanks!

robertbasic commented 8 years ago

I have patched it locally the same, it works for me!