mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Fix preview and undo hunk for dos line endings
This commit is contained in:
@@ -278,7 +278,7 @@ endfunction
|
|||||||
function! s:undo(hunk_diff)
|
function! s:undo(hunk_diff)
|
||||||
" Apply reverse patch to buffer.
|
" Apply reverse patch to buffer.
|
||||||
let hunk = gitgutter#diff#parse_hunk(split(a:hunk_diff, '\n')[4])
|
let hunk = gitgutter#diff#parse_hunk(split(a:hunk_diff, '\n')[4])
|
||||||
let lines = map(split(a:hunk_diff, '\n')[5:], 'v:val[1:]')
|
let lines = map(split(a:hunk_diff, '\r\?\n')[5:], 'v:val[1:]')
|
||||||
let lnum = hunk[2]
|
let lnum = hunk[2]
|
||||||
let added_only = hunk[1] == 0 && hunk[3] > 0
|
let added_only = hunk[1] == 0 && hunk[3] > 0
|
||||||
let removed_only = hunk[1] > 0 && hunk[3] == 0
|
let removed_only = hunk[1] > 0 && hunk[3] == 0
|
||||||
@@ -295,7 +295,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
function! s:preview(hunk_diff)
|
function! s:preview(hunk_diff)
|
||||||
let lines = split(a:hunk_diff, '\n')
|
let lines = split(a:hunk_diff, '\r\?\n')
|
||||||
let header = lines[0:4]
|
let header = lines[0:4]
|
||||||
let body = lines[5:]
|
let body = lines[5:]
|
||||||
|
|
||||||
|
|||||||
10
test/fixture_dos.txt
Normal file
10
test/fixture_dos.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
d
|
||||||
|
e
|
||||||
|
f
|
||||||
|
g
|
||||||
|
h
|
||||||
|
i
|
||||||
|
j
|
||||||
@@ -55,6 +55,7 @@ function SetUp()
|
|||||||
call system("git init ".s:test_repo.
|
call system("git init ".s:test_repo.
|
||||||
\ " && cd ".s:test_repo.
|
\ " && cd ".s:test_repo.
|
||||||
\ " && cp ../fixture.txt .".
|
\ " && cp ../fixture.txt .".
|
||||||
|
\ " && cp ../fixture_dos.txt .".
|
||||||
\ " && git add . && git commit -m 'initial'".
|
\ " && git add . && git commit -m 'initial'".
|
||||||
\ " && git config diff.mnemonicPrefix false")
|
\ " && git config diff.mnemonicPrefix false")
|
||||||
execute ':cd' s:test_repo
|
execute ':cd' s:test_repo
|
||||||
@@ -349,6 +350,34 @@ function Test_hunk_outside_noop()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function Test_preview_foo()
|
||||||
|
normal 5Gi*
|
||||||
|
GitGutterPreviewHunk
|
||||||
|
|
||||||
|
wincmd P
|
||||||
|
call assert_equal(2, line('$'))
|
||||||
|
call assert_equal('-e', getline(1))
|
||||||
|
call assert_equal('+*e', getline(2))
|
||||||
|
wincmd p
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function Test_preview_dos_foo()
|
||||||
|
edit! fixture_dos.txt
|
||||||
|
|
||||||
|
normal 5Gi*
|
||||||
|
GitGutterPreviewHunk
|
||||||
|
|
||||||
|
wincmd P
|
||||||
|
call assert_equal(2, line('$'))
|
||||||
|
call assert_equal('-e', getline(1))
|
||||||
|
call assert_equal('+*e', getline(2))
|
||||||
|
wincmd p
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Test_hunk_stage()
|
function Test_hunk_stage()
|
||||||
let _shell = &shell
|
let _shell = &shell
|
||||||
set shell=foo
|
set shell=foo
|
||||||
@@ -657,6 +686,19 @@ function Test_hunk_undo()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function Test_hunk_undo_dos()
|
||||||
|
edit! fixture_dos.txt
|
||||||
|
|
||||||
|
normal 5Gi*
|
||||||
|
GitGutterUndoHunk
|
||||||
|
|
||||||
|
call s:assert_signs([], 'fixture_dos.txt')
|
||||||
|
call assert_equal([], s:git_diff())
|
||||||
|
call assert_equal([], s:git_diff_staged())
|
||||||
|
call assert_equal('e', getline(5))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function Test_undo_nearby_hunk()
|
function Test_undo_nearby_hunk()
|
||||||
execute "normal! 2Gox\<CR>y\<CR>z"
|
execute "normal! 2Gox\<CR>y\<CR>z"
|
||||||
normal 2jdd
|
normal 2jdd
|
||||||
|
|||||||
Reference in New Issue
Block a user