Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 6 | test_description='git apply boundary tests' |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 7 | |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | L="c d e f g h i j k l m n o p q r s t u v w x" |
| 11 | |
| 12 | test_expect_success setup ' |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 13 | test_write_lines b $L y >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 14 | cat victim >original && |
| 15 | git update-index --add victim && |
| 16 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 17 | # add to the head |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 18 | test_write_lines a b $L y >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 19 | cat victim >add-a-expect && |
| 20 | git diff victim >add-a-patch.with && |
| 21 | git diff --unified=0 >add-a-patch.without && |
| 22 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 23 | # insert at line two |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 24 | test_write_lines b a $L y >victim && |
Junio C Hamano | ed0f47a | 2008-08-30 13:20:31 -0700 | [diff] [blame] | 25 | cat victim >insert-a-expect && |
| 26 | git diff victim >insert-a-patch.with && |
| 27 | git diff --unified=0 >insert-a-patch.without && |
| 28 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 29 | # modify at the head |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 30 | test_write_lines a $L y >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 31 | cat victim >mod-a-expect && |
| 32 | git diff victim >mod-a-patch.with && |
| 33 | git diff --unified=0 >mod-a-patch.without && |
| 34 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 35 | # remove from the head |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 36 | test_write_lines $L y >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 37 | cat victim >del-a-expect && |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 38 | git diff victim >del-a-patch.with && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 39 | git diff --unified=0 >del-a-patch.without && |
| 40 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 41 | # add to the tail |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 42 | test_write_lines b $L y z >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 43 | cat victim >add-z-expect && |
| 44 | git diff victim >add-z-patch.with && |
| 45 | git diff --unified=0 >add-z-patch.without && |
| 46 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 47 | # modify at the tail |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 48 | test_write_lines b $L z >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 49 | cat victim >mod-z-expect && |
| 50 | git diff victim >mod-z-patch.with && |
| 51 | git diff --unified=0 >mod-z-patch.without && |
| 52 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 53 | # remove from the tail |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 54 | test_write_lines b $L >victim && |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 55 | cat victim >del-z-expect && |
Jeff King | 8fb2687 | 2015-03-20 06:06:15 -0400 | [diff] [blame] | 56 | git diff victim >del-z-patch.with && |
| 57 | git diff --unified=0 >del-z-patch.without |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 58 | |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 59 | # done |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 60 | ' |
| 61 | |
| 62 | for with in with without |
| 63 | do |
| 64 | case "$with" in |
| 65 | with) u= ;; |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 66 | without) u=--unidiff-zero ;; |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 67 | esac |
Junio C Hamano | ed0f47a | 2008-08-30 13:20:31 -0700 | [diff] [blame] | 68 | for kind in add-a add-z insert-a mod-a mod-z del-a del-z |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 69 | do |
| 70 | test_expect_success "apply $kind-patch $with context" ' |
| 71 | cat original >victim && |
| 72 | git update-index victim && |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 73 | git apply --index $u "$kind-patch.$with" && |
| 74 | test_cmp "$kind-expect" victim |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 75 | ' |
| 76 | done |
| 77 | done |
| 78 | |
Junio C Hamano | ed0f47a | 2008-08-30 13:20:31 -0700 | [diff] [blame] | 79 | for kind in add-a add-z insert-a mod-a mod-z del-a del-z |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 80 | do |
| 81 | rm -f $kind-ng.without |
| 82 | sed -e "s/^diff --git /diff /" \ |
| 83 | -e '/^index /d' \ |
| 84 | <$kind-patch.without >$kind-ng.without |
| 85 | test_expect_success "apply non-git $kind-patch without context" ' |
| 86 | cat original >victim && |
| 87 | git update-index victim && |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 88 | git apply --unidiff-zero --index "$kind-ng.without" && |
| 89 | test_cmp "$kind-expect" victim |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 90 | ' |
| 91 | done |
| 92 | |
Junio C Hamano | ee5a317 | 2008-04-06 19:21:45 -0700 | [diff] [blame] | 93 | test_expect_success 'two lines' ' |
Junio C Hamano | ee5a317 | 2008-04-06 19:21:45 -0700 | [diff] [blame] | 94 | >file && |
| 95 | git add file && |
| 96 | echo aaa >file && |
| 97 | git diff >patch && |
| 98 | git add file && |
| 99 | echo bbb >file && |
| 100 | git add file && |
| 101 | test_must_fail git apply --check patch |
Junio C Hamano | ee5a317 | 2008-04-06 19:21:45 -0700 | [diff] [blame] | 102 | ' |
| 103 | |
Björn Gustavsson | 24ff4d5 | 2010-03-06 15:30:29 +0100 | [diff] [blame] | 104 | test_expect_success 'apply patch with 3 context lines matching at end' ' |
Martin Ågren | 289218d | 2020-08-06 22:08:54 +0200 | [diff] [blame] | 105 | test_write_lines a b c d >file && |
Björn Gustavsson | 24ff4d5 | 2010-03-06 15:30:29 +0100 | [diff] [blame] | 106 | git add file && |
| 107 | echo e >>file && |
| 108 | git diff >patch && |
| 109 | >file && |
| 110 | test_must_fail git apply patch |
| 111 | ' |
| 112 | |
Junio C Hamano | 4be6096 | 2006-09-17 01:04:24 -0700 | [diff] [blame] | 113 | test_done |