Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='apply same filename' |
| 4 | |
Ævar Arnfjörð Bjarmason | f54f48f | 2021-10-31 00:24:18 +0200 | [diff] [blame] | 5 | |
| 6 | TEST_PASSES_SANITIZE_LEAK=true |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 9 | modify () { |
| 10 | sed -e "$1" < "$2" > "$2".x && |
| 11 | mv "$2".x "$2" |
| 12 | } |
| 13 | |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 14 | test_expect_success setup ' |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 15 | test_write_lines a b c d e f g h i j k l m >same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 16 | cp same_fn other_fn && |
| 17 | git add same_fn other_fn && |
| 18 | git commit -m initial |
| 19 | ' |
| 20 | test_expect_success 'apply same filename with independent changes' ' |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 21 | modify "s/^d/z/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 22 | git diff > patch0 && |
| 23 | git add same_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 24 | modify "s/^i/y/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 25 | git diff >> patch0 && |
| 26 | cp same_fn same_fn2 && |
| 27 | git reset --hard && |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 28 | git apply patch0 && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 29 | test_cmp same_fn same_fn2 |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 30 | ' |
| 31 | |
| 32 | test_expect_success 'apply same filename with overlapping changes' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 33 | git reset --hard && |
Jonathan Tan | b0f266d | 2020-10-20 15:04:52 -0700 | [diff] [blame] | 34 | |
| 35 | # Store same_fn so that we can check apply -R in next test |
| 36 | cp same_fn same_fn1 && |
| 37 | |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 38 | modify "s/^d/z/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 39 | git diff > patch0 && |
| 40 | git add same_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 41 | modify "s/^e/y/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 42 | git diff >> patch0 && |
| 43 | cp same_fn same_fn2 && |
| 44 | git reset --hard && |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 45 | git apply patch0 && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 46 | test_cmp same_fn same_fn2 |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 47 | ' |
| 48 | |
Jonathan Tan | b0f266d | 2020-10-20 15:04:52 -0700 | [diff] [blame] | 49 | test_expect_success 'apply same filename with overlapping changes, in reverse' ' |
| 50 | git apply -R patch0 && |
| 51 | test_cmp same_fn same_fn1 |
| 52 | ' |
| 53 | |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 54 | test_expect_success 'apply same new filename after rename' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 55 | git reset --hard && |
| 56 | git mv same_fn new_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 57 | modify "s/^d/z/" new_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 58 | git add new_fn && |
| 59 | git diff -M --cached > patch1 && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 60 | modify "s/^e/y/" new_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 61 | git diff >> patch1 && |
| 62 | cp new_fn new_fn2 && |
| 63 | git reset --hard && |
| 64 | git apply --index patch1 && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 65 | test_cmp new_fn new_fn2 |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 66 | ' |
| 67 | |
| 68 | test_expect_success 'apply same old filename after rename -- should fail.' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 69 | git reset --hard && |
| 70 | git mv same_fn new_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 71 | modify "s/^d/z/" new_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 72 | git add new_fn && |
| 73 | git diff -M --cached > patch1 && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 74 | git mv new_fn same_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 75 | modify "s/^e/y/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 76 | git diff >> patch1 && |
| 77 | git reset --hard && |
| 78 | test_must_fail git apply patch1 |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' ' |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 82 | git reset --hard && |
| 83 | git mv same_fn new_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 84 | modify "s/^d/z/" new_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 85 | git add new_fn && |
| 86 | git diff -M --cached > patch1 && |
| 87 | git commit -m "a rename" && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 88 | git mv other_fn same_fn && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 89 | modify "s/^e/y/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 90 | git add same_fn && |
| 91 | git diff -M --cached >> patch1 && |
Johannes Sixt | 41872fd | 2008-07-04 08:43:19 +0200 | [diff] [blame] | 92 | modify "s/^g/x/" same_fn && |
Don Zickus | 7a07841 | 2008-06-27 14:39:12 -0400 | [diff] [blame] | 93 | git diff >> patch1 && |
| 94 | git reset --hard HEAD^ && |
| 95 | git apply patch1 |
| 96 | ' |
| 97 | |
| 98 | test_done |