From e2056e54c50c6f3fbf386108eeb013e2a7f14ae3 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Mon, 5 Jun 2023 10:52:10 +0100 Subject: [PATCH] Add test for clean/smudge filter See #796. --- test/.gitattributes | 1 + test/.gitconfig | 6 ++++++ test/fixture.foo | 4 ++++ test/test_gitgutter.vim | 31 ++++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/.gitattributes create mode 100644 test/.gitconfig create mode 100644 test/fixture.foo diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 0000000..a2ef04b --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1 @@ +*.foo filter=reverse diff=reverse diff --git a/test/.gitconfig b/test/.gitconfig new file mode 100644 index 0000000..da9456f --- /dev/null +++ b/test/.gitconfig @@ -0,0 +1,6 @@ +[filter "reverse"] + clean = "rev" + smudge = "rev" + +[diff "reverse"] + textconv = "cat" diff --git a/test/fixture.foo b/test/fixture.foo new file mode 100644 index 0000000..f384549 --- /dev/null +++ b/test/fixture.foo @@ -0,0 +1,4 @@ +one +two +three +four diff --git a/test/test_gitgutter.vim b/test/test_gitgutter.vim index a3d5a0d..d45fe5a 100644 --- a/test/test_gitgutter.vim +++ b/test/test_gitgutter.vim @@ -54,6 +54,9 @@ endfunction function SetUp() call system("git init ".s:test_repo. \ " && cd ".s:test_repo. + \ " && cp ../.gitconfig .". + \ " && cp ../.gitattributes .". + \ " && cp ../fixture.foo .". \ " && cp ../fixture.txt .". \ " && cp ../fixture_dos.txt .". \ " && git add . && git commit -m 'initial'". @@ -76,7 +79,7 @@ function TearDown() silent! execute s:bufnr+1.',$bdelete!' execute ':cd' s:current_dir - call system("rm -rf ".s:test_repo) + " call system("rm -rf ".s:test_repo) endfunction " @@ -1179,3 +1182,29 @@ function Test_assume_unchanged() call s:trigger_gitgutter() call s:assert_signs([], 'fixture.txt') endfunction + + +function Test_clean_smudge_filter() + call system("git config --local include.path ../.gitconfig") + call system("rm fixture.foo && git checkout fixture.foo") + + func Answer(char) + call feedkeys(a:char."\") + endfunc + + edit fixture.foo + call setline(2, ['A']) + call setline(4, ['B']) + call s:trigger_gitgutter() + normal! 2G + call timer_start(100, {-> Answer('y')} ) + GitGutterStageHunk + call s:trigger_gitgutter() + + let expected = [ + \ {'lnum': 2, 'id': 23, 'name': 'GitGutterLineModified', 'priority': 10, 'group': 'gitgutter'}, + \ {'lnum': 4, 'id': 24, 'name': 'GitGutterLineModified', 'priority': 10, 'group': 'gitgutter'} + \ ] + " call s:assert_signs(expected, 'fixture.foo') + call s:assert_signs([], 'fixture.foo') +endfunction