]>
Commit | Line | Data |
---|---|---|
7a07841c DZ |
1 | #!/bin/sh |
2 | ||
3 | test_description='apply same filename' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
41872fd5 JS |
7 | modify () { |
8 | sed -e "$1" < "$2" > "$2".x && | |
9 | mv "$2".x "$2" | |
10 | } | |
11 | ||
7a07841c DZ |
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' ' | |
41872fd5 | 22 | modify "s/^d/z/" same_fn && |
7a07841c DZ |
23 | git diff > patch0 && |
24 | git add same_fn && | |
41872fd5 | 25 | modify "s/^i/y/" same_fn && |
7a07841c DZ |
26 | git diff >> patch0 && |
27 | cp same_fn same_fn2 && | |
28 | git reset --hard && | |
3604e7c5 | 29 | git apply patch0 && |
4fdf71be | 30 | test_cmp same_fn same_fn2 |
7a07841c DZ |
31 | ' |
32 | ||
33 | test_expect_success 'apply same filename with overlapping changes' ' | |
a48fcd83 | 34 | git reset --hard && |
41872fd5 | 35 | modify "s/^d/z/" same_fn && |
7a07841c DZ |
36 | git diff > patch0 && |
37 | git add same_fn && | |
41872fd5 | 38 | modify "s/^e/y/" same_fn && |
7a07841c DZ |
39 | git diff >> patch0 && |
40 | cp same_fn same_fn2 && | |
41 | git reset --hard && | |
3604e7c5 | 42 | git apply patch0 && |
4fdf71be | 43 | test_cmp same_fn same_fn2 |
7a07841c DZ |
44 | ' |
45 | ||
46 | test_expect_success 'apply same new filename after rename' ' | |
a48fcd83 JN |
47 | git reset --hard && |
48 | git mv same_fn new_fn && | |
41872fd5 | 49 | modify "s/^d/z/" new_fn && |
7a07841c DZ |
50 | git add new_fn && |
51 | git diff -M --cached > patch1 && | |
41872fd5 | 52 | modify "s/^e/y/" new_fn && |
7a07841c DZ |
53 | git diff >> patch1 && |
54 | cp new_fn new_fn2 && | |
55 | git reset --hard && | |
56 | git apply --index patch1 && | |
4fdf71be | 57 | test_cmp new_fn new_fn2 |
7a07841c DZ |
58 | ' |
59 | ||
60 | test_expect_success 'apply same old filename after rename -- should fail.' ' | |
a48fcd83 JN |
61 | git reset --hard && |
62 | git mv same_fn new_fn && | |
41872fd5 | 63 | modify "s/^d/z/" new_fn && |
7a07841c DZ |
64 | git add new_fn && |
65 | git diff -M --cached > patch1 && | |
a48fcd83 | 66 | git mv new_fn same_fn && |
41872fd5 | 67 | modify "s/^e/y/" same_fn && |
7a07841c DZ |
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.' ' | |
a48fcd83 JN |
74 | git reset --hard && |
75 | git mv same_fn new_fn && | |
41872fd5 | 76 | modify "s/^d/z/" new_fn && |
7a07841c DZ |
77 | git add new_fn && |
78 | git diff -M --cached > patch1 && | |
79 | git commit -m "a rename" && | |
a48fcd83 | 80 | git mv other_fn same_fn && |
41872fd5 | 81 | modify "s/^e/y/" same_fn && |
7a07841c DZ |
82 | git add same_fn && |
83 | git diff -M --cached >> patch1 && | |
41872fd5 | 84 | modify "s/^g/x/" same_fn && |
7a07841c DZ |
85 | git diff >> patch1 && |
86 | git reset --hard HEAD^ && | |
87 | git apply patch1 | |
88 | ' | |
89 | ||
90 | test_done |