]>
Commit | Line | Data |
---|---|---|
7a07841c DZ |
1 | #!/bin/sh |
2 | ||
3 | test_description='apply same filename' | |
4 | ||
f54f48fc ÆAB |
5 | |
6 | TEST_PASSES_SANITIZE_LEAK=true | |
7a07841c DZ |
7 | . ./test-lib.sh |
8 | ||
41872fd5 JS |
9 | modify () { |
10 | sed -e "$1" < "$2" > "$2".x && | |
11 | mv "$2".x "$2" | |
12 | } | |
13 | ||
7a07841c | 14 | test_expect_success setup ' |
08495412 | 15 | test_write_lines a b c d e f g h i j k l m >same_fn && |
7a07841c DZ |
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' ' | |
41872fd5 | 21 | modify "s/^d/z/" same_fn && |
7a07841c DZ |
22 | git diff > patch0 && |
23 | git add same_fn && | |
41872fd5 | 24 | modify "s/^i/y/" same_fn && |
7a07841c DZ |
25 | git diff >> patch0 && |
26 | cp same_fn same_fn2 && | |
27 | git reset --hard && | |
3604e7c5 | 28 | git apply patch0 && |
4fdf71be | 29 | test_cmp same_fn same_fn2 |
7a07841c DZ |
30 | ' |
31 | ||
32 | test_expect_success 'apply same filename with overlapping changes' ' | |
a48fcd83 | 33 | git reset --hard && |
b0f266de JT |
34 | |
35 | # Store same_fn so that we can check apply -R in next test | |
36 | cp same_fn same_fn1 && | |
37 | ||
41872fd5 | 38 | modify "s/^d/z/" same_fn && |
7a07841c DZ |
39 | git diff > patch0 && |
40 | git add same_fn && | |
41872fd5 | 41 | modify "s/^e/y/" same_fn && |
7a07841c DZ |
42 | git diff >> patch0 && |
43 | cp same_fn same_fn2 && | |
44 | git reset --hard && | |
3604e7c5 | 45 | git apply patch0 && |
4fdf71be | 46 | test_cmp same_fn same_fn2 |
7a07841c DZ |
47 | ' |
48 | ||
b0f266de JT |
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 | ||
7a07841c | 54 | test_expect_success 'apply same new filename after rename' ' |
a48fcd83 JN |
55 | git reset --hard && |
56 | git mv same_fn new_fn && | |
41872fd5 | 57 | modify "s/^d/z/" new_fn && |
7a07841c DZ |
58 | git add new_fn && |
59 | git diff -M --cached > patch1 && | |
41872fd5 | 60 | modify "s/^e/y/" new_fn && |
7a07841c DZ |
61 | git diff >> patch1 && |
62 | cp new_fn new_fn2 && | |
63 | git reset --hard && | |
64 | git apply --index patch1 && | |
4fdf71be | 65 | test_cmp new_fn new_fn2 |
7a07841c DZ |
66 | ' |
67 | ||
68 | test_expect_success 'apply same old filename after rename -- should fail.' ' | |
a48fcd83 JN |
69 | git reset --hard && |
70 | git mv same_fn new_fn && | |
41872fd5 | 71 | modify "s/^d/z/" new_fn && |
7a07841c DZ |
72 | git add new_fn && |
73 | git diff -M --cached > patch1 && | |
a48fcd83 | 74 | git mv new_fn same_fn && |
41872fd5 | 75 | modify "s/^e/y/" same_fn && |
7a07841c DZ |
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.' ' | |
a48fcd83 JN |
82 | git reset --hard && |
83 | git mv same_fn new_fn && | |
41872fd5 | 84 | modify "s/^d/z/" new_fn && |
7a07841c DZ |
85 | git add new_fn && |
86 | git diff -M --cached > patch1 && | |
87 | git commit -m "a rename" && | |
a48fcd83 | 88 | git mv other_fn same_fn && |
41872fd5 | 89 | modify "s/^e/y/" same_fn && |
7a07841c DZ |
90 | git add same_fn && |
91 | git diff -M --cached >> patch1 && | |
41872fd5 | 92 | modify "s/^g/x/" same_fn && |
7a07841c DZ |
93 | git diff >> patch1 && |
94 | git reset --hard HEAD^ && | |
95 | git apply patch1 | |
96 | ' | |
97 | ||
98 | test_done |