aboutsummaryrefslogtreecommitdiff
path: root/t/t4124-apply-ws-rule.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t4124-apply-ws-rule.sh')
-rwxr-xr-xt/t4124-apply-ws-rule.sh289
1 files changed, 289 insertions, 0 deletions
diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
index 485c7d2d12..205d86d05e 100755
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
@@ -556,4 +556,293 @@ test_expect_success 'whitespace check skipped for excluded paths' '
git apply --include=used --stat --whitespace=error <patch
'
+test_expect_success 'check incomplete lines (setup)' '
+ rm -f .gitattributes &&
+ git config core.whitespace incomplete-line
+'
+
+test_expect_success 'no incomplete context line (not an error)' '
+ test_when_finished "rm -f sample*-i patch patch-new target" &&
+ test_write_lines 1 2 3 "" 4 5 >sample-i &&
+ test_write_lines 1 2 3 "" 0 5 >sample2-i &&
+ cat sample-i >target &&
+ git add target &&
+ cat sample2-i >target &&
+ git diff-files -p target >patch &&
+ sed -e "s/^ $//" <patch >patch-new &&
+
+ cat sample-i >target &&
+ git apply --whitespace=fix <patch-new 2>error &&
+ test_cmp sample2-i target &&
+ test_must_be_empty error
+'
+
+test_expect_success 'incomplete context line (not an error)' '
+ (test_write_lines 1 2 3 4 5 && printf 6) >sample-i &&
+ (test_write_lines 1 2 3 0 5 && printf 6) >sample2-i &&
+ cat sample-i >target &&
+ git add target &&
+ cat sample2-i >target &&
+ git diff-files -p target >patch &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error <patch &&
+ test_cmp sample2-i target &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error --check <patch 2>error &&
+ test_cmp sample-i target &&
+ test_must_be_empty error &&
+
+ cat sample2-i >target &&
+ git apply --whitespace=error -R <patch &&
+ test_cmp sample-i target &&
+
+ cat sample2-i >target &&
+ git apply -R --whitespace=error --check <patch 2>error &&
+ test_cmp sample2-i target &&
+ test_must_be_empty error
+'
+
+test_expect_success 'last line made incomplete (error)' '
+ test_write_lines 1 2 3 4 5 6 >sample &&
+ (test_write_lines 1 2 3 4 5 && printf 6) >sample-i &&
+ cat sample >target &&
+ git add target &&
+ cat sample-i >target &&
+ git diff-files -p target >patch &&
+
+ cat sample >target &&
+ test_must_fail git apply --whitespace=error <patch 2>error &&
+ test_grep "no newline" error &&
+
+ cat sample >target &&
+ test_must_fail git apply --whitespace=error --check <patch 2>actual &&
+ test_cmp sample target &&
+ cat >expect <<-\EOF &&
+ <stdin>:10: no newline at the end of file.
+ 6
+ error: 1 line adds whitespace errors.
+ EOF
+ test_cmp expect actual &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error -R <patch &&
+ test_cmp sample target &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error --check -R <patch 2>error &&
+ test_cmp sample-i target &&
+ test_must_be_empty error &&
+
+ cat sample >target &&
+ git apply --whitespace=fix <patch &&
+ test_cmp sample target
+'
+
+test_expect_success 'incomplete line removed at the end (not an error)' '
+ (test_write_lines 1 2 3 4 5 && printf 6) >sample-i &&
+ test_write_lines 1 2 3 4 5 6 >sample &&
+ cat sample-i >target &&
+ git add target &&
+ cat sample >target &&
+ git diff-files -p target >patch &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error <patch &&
+ test_cmp sample target &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error --check <patch 2>error &&
+ test_cmp sample-i target &&
+ test_must_be_empty error &&
+
+ cat sample >target &&
+ test_must_fail git apply --whitespace=error -R <patch 2>error &&
+ test_grep "no newline" error &&
+
+ cat sample >target &&
+ test_must_fail git apply --whitespace=error --check -R <patch 2>actual &&
+ test_cmp sample target &&
+ cat >expect <<-\EOF &&
+ <stdin>:9: no newline at the end of file.
+ 6
+ error: 1 line adds whitespace errors.
+ EOF
+ test_cmp expect actual &&
+
+ cat sample >target &&
+ git apply --whitespace=fix -R <patch &&
+ test_cmp sample target
+'
+
+test_expect_success 'incomplete line corrected at the end (not an error)' '
+ (test_write_lines 1 2 3 4 5 && printf 6) >sample-i &&
+ test_write_lines 1 2 3 4 5 7 >sample3 &&
+ cat sample-i >target &&
+ git add target &&
+ cat sample3 >target &&
+ git diff-files -p target >patch &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error <patch &&
+ test_cmp sample3 target &&
+
+ cat sample-i >target &&
+ git apply --whitespace=error --check <patch 2>error &&
+ test_cmp sample-i target &&
+ test_must_be_empty error &&
+
+ cat sample3 >target &&
+ test_must_fail git apply --whitespace=error -R <patch 2>error &&
+ test_grep "no newline" error &&
+
+ cat sample3 >target &&
+ test_must_fail git apply --whitespace=error -R --check <patch 2>actual &&
+ test_cmp sample3 target &&
+ cat >expect <<-\EOF &&
+ <stdin>:9: no newline at the end of file.
+ 6
+ error: 1 line adds whitespace errors.
+ EOF
+ test_cmp expect actual &&
+
+ cat sample3 >target &&
+ git apply --whitespace=fix -R <patch &&
+ test_cmp sample target
+'
+
+test_expect_success 'incomplete line modified at the end (error)' '
+ (test_write_lines 1 2 3 4 5 && printf 6) >sample-i &&
+ (test_write_lines 1 2 3 4 5 && printf 7) >sample3-i &&
+ test_write_lines 1 2 3 4 5 6 >sample &&
+ test_write_lines 1 2 3 4 5 7 >sample3 &&
+ cat sample-i >target &&
+ git add target &&
+ cat sample3-i >target &&
+ git diff-files -p target >patch &&
+
+ cat sample-i >target &&
+ test_must_fail git apply --whitespace=error <patch 2>error &&
+ test_grep "no newline" error &&
+
+ cat sample-i >target &&
+ test_must_fail git apply --whitespace=error --check <patch 2>actual &&
+ test_cmp sample-i target &&
+ cat >expect <<-\EOF &&
+ <stdin>:11: no newline at the end of file.
+ 7
+ error: 1 line adds whitespace errors.
+ EOF
+ test_cmp expect actual &&
+
+ cat sample3-i >target &&
+ test_must_fail git apply --whitespace=error -R <patch 2>error &&
+ test_grep "no newline" error &&
+
+ cat sample3-i >target &&
+ test_must_fail git apply --whitespace=error --check -R <patch 2>actual &&
+ test_cmp sample3-i target &&
+ cat >expect <<-\EOF &&
+ <stdin>:9: no newline at the end of file.
+ 6
+ error: 1 line adds whitespace errors.
+ EOF
+ test_cmp expect actual &&
+
+ cat sample-i >target &&
+ git apply --whitespace=fix <patch &&
+ test_cmp sample3 target &&
+
+ cat sample3-i >target &&
+ git apply --whitespace=fix -R <patch &&
+ test_cmp sample target
+'
+
+test_expect_success "incomplete-line error is disabled for symlinks" '
+ test_when_finished "git reset" &&
+ test_when_finished "rm -f patch.txt" &&
+ oneblob=$(printf "one" | git hash-object --stdin -w -t blob) &&
+ twoblob=$(printf "two" | git hash-object --stdin -w -t blob) &&
+
+ oneshort=$(git rev-parse --short $oneblob) &&
+ twoshort=$(git rev-parse --short $twoblob) &&
+
+ cat >patch0.txt <<-EOF &&
+ diff --git a/mylink b/mylink
+ index $oneshort..$twoshort 120000
+ --- a/mylink
+ +++ b/mylink
+ @@ -1 +1 @@
+ -one
+ \ No newline at end of file
+ +two
+ \ No newline at end of file
+ EOF
+
+ # the index has the preimage symlink
+ git update-index --add --cacheinfo "120000,$oneblob,mylink" &&
+
+ # check the patch going forward and reverse
+ git -c core.whitespace=incomplete apply --cached --check \
+ --whitespace=error patch0.txt &&
+
+ git update-index --add --cacheinfo "120000,$twoblob,mylink" &&
+ git -c core.whitespace=incomplete apply --cached --check \
+ --whitespace=error -R patch0.txt &&
+
+ # the patch turns it into the postimage symlink
+ git update-index --add --cacheinfo "120000,$oneblob,mylink" &&
+ git -c core.whitespace=incomplete apply --cached --whitespace=error \
+ patch0.txt &&
+
+ # and then back.
+ git -c core.whitespace=incomplete apply --cached -R --whitespace=error \
+ patch0.txt &&
+
+ # a text file turns into a symlink
+ cat >patch1.txt <<-EOF &&
+ diff --git a/mylink b/mylink
+ deleted file mode 100644
+ index $oneshort..0000000
+ --- a/mylink
+ +++ /dev/null
+ @@ -1 +0,0 @@
+ -one
+ \ No newline at end of file
+ diff --git a/mylink b/mylink
+ new file mode 120000
+ index 0000000..$twoshort
+ --- /dev/null
+ +++ b/mylink
+ @@ -0,0 +1 @@
+ +two
+ \ No newline at end of file
+ EOF
+
+ # the index has the preimage text
+ git update-index --cacheinfo "100644,$oneblob,mylink" &&
+
+ # check
+ git -c core.whitespace=incomplete apply --cached \
+ --check --whitespace=error patch1.txt &&
+
+ # reverse, leaving an incomplete text file, should error
+ git update-index --cacheinfo "120000,$twoblob,mylink" &&
+ test_must_fail git -c core.whitespace=incomplete \
+ apply --cached --check --whitespace=error -R patch1.txt &&
+
+ # apply to create a symbolic link
+ git update-index --cacheinfo "100644,$oneblob,mylink" &&
+ git -c core.whitespace=incomplete apply --cached --whitespace=error \
+ patch1.txt &&
+
+ # turning it back into an incomplete text file is an error
+ test_must_fail git -c core.whitespace=incomplete \
+ apply --cached --whitespace=error -R patch1.txt
+
+
+
+'
+
test_done