diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-06-28 12:53:32 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-06-28 12:53:32 -0700 |
commit | 5eb8da850860839bdf38ab80079eb8875b764431 (patch) | |
tree | a2156eaf3bd403dd7b1ac4e78412dba283fa78fa | |
parent | Merge branch 'jk/fetch-all-peeled-fix' (diff) | |
parent | add -p: fix counting empty context lines in edited patches (diff) | |
download | tgif-5eb8da850860839bdf38ab80079eb8875b764431.tar.xz |
Merge branch 'pw/add-p-recount'
When user edits the patch in "git add -p" and the user's editor is
set to strip trailing whitespaces indiscriminately, an empty line
that is unchanged in the patch would become completely empty
(instead of a line with a sole SP on it). The code introduced in
Git 2.17 timeframe failed to parse such a patch, but now it learned
to notice the situation and cope with it.
* pw/add-p-recount:
add -p: fix counting empty context lines in edited patches
-rwxr-xr-x | git-add--interactive.perl | 2 | ||||
-rwxr-xr-x | t/t3701-add-interactive.sh | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 36f38ced90..20eb81cc92 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -1062,7 +1062,7 @@ sub recount_edited_hunk { $o_cnt++; } elsif ($mode eq '+') { $n_cnt++; - } elsif ($mode eq ' ') { + } elsif ($mode eq ' ' or $mode eq "\n") { $o_cnt++; $n_cnt++; } diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index b170fb02b8..3e9139dca8 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -175,6 +175,49 @@ test_expect_success 'real edit works' ' diff_cmp expected output ' +test_expect_success 'setup file' ' + test_write_lines a "" b "" c >file && + git add file && + test_write_lines a "" d "" c >file +' + +test_expect_success 'setup patch' ' + SP=" " && + NULL="" && + cat >patch <<-EOF + @@ -1,4 +1,4 @@ + a + $NULL + -b + +f + $SP + c + EOF +' + +test_expect_success 'setup expected' ' + cat >expected <<-EOF + diff --git a/file b/file + index b5dd6c9..f910ae9 100644 + --- a/file + +++ b/file + @@ -1,5 +1,5 @@ + a + $SP + -f + +d + $SP + c + EOF +' + +test_expect_success 'edit can strip spaces from empty context lines' ' + test_write_lines e n q | git add -p 2>error && + test_must_be_empty error && + git diff >output && + diff_cmp expected output +' + test_expect_success 'skip files similarly as commit -a' ' git reset && echo file >.gitignore && |