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