]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4127-apply-same-fn.sh
Merge branch 'ak/protect-any-current-branch'
[thirdparty/git.git] / t / t4127-apply-same-fn.sh
1 #!/bin/sh
2
3 test_description='apply same filename'
4
5
6 TEST_PASSES_SANITIZE_LEAK=true
7 . ./test-lib.sh
8
9 modify () {
10 sed -e "$1" < "$2" > "$2".x &&
11 mv "$2".x "$2"
12 }
13
14 test_expect_success setup '
15 for i in a b c d e f g h i j k l m
16 do
17 echo $i
18 done >same_fn &&
19 cp same_fn other_fn &&
20 git add same_fn other_fn &&
21 git commit -m initial
22 '
23 test_expect_success 'apply same filename with independent changes' '
24 modify "s/^d/z/" same_fn &&
25 git diff > patch0 &&
26 git add same_fn &&
27 modify "s/^i/y/" same_fn &&
28 git diff >> patch0 &&
29 cp same_fn same_fn2 &&
30 git reset --hard &&
31 git apply patch0 &&
32 test_cmp same_fn same_fn2
33 '
34
35 test_expect_success 'apply same filename with overlapping changes' '
36 git reset --hard &&
37
38 # Store same_fn so that we can check apply -R in next test
39 cp same_fn same_fn1 &&
40
41 modify "s/^d/z/" same_fn &&
42 git diff > patch0 &&
43 git add same_fn &&
44 modify "s/^e/y/" same_fn &&
45 git diff >> patch0 &&
46 cp same_fn same_fn2 &&
47 git reset --hard &&
48 git apply patch0 &&
49 test_cmp same_fn same_fn2
50 '
51
52 test_expect_success 'apply same filename with overlapping changes, in reverse' '
53 git apply -R patch0 &&
54 test_cmp same_fn same_fn1
55 '
56
57 test_expect_success 'apply same new filename after rename' '
58 git reset --hard &&
59 git mv same_fn new_fn &&
60 modify "s/^d/z/" new_fn &&
61 git add new_fn &&
62 git diff -M --cached > patch1 &&
63 modify "s/^e/y/" new_fn &&
64 git diff >> patch1 &&
65 cp new_fn new_fn2 &&
66 git reset --hard &&
67 git apply --index patch1 &&
68 test_cmp new_fn new_fn2
69 '
70
71 test_expect_success 'apply same old filename after rename -- should fail.' '
72 git reset --hard &&
73 git mv same_fn new_fn &&
74 modify "s/^d/z/" new_fn &&
75 git add new_fn &&
76 git diff -M --cached > patch1 &&
77 git mv new_fn same_fn &&
78 modify "s/^e/y/" same_fn &&
79 git diff >> patch1 &&
80 git reset --hard &&
81 test_must_fail git apply patch1
82 '
83
84 test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' '
85 git reset --hard &&
86 git mv same_fn new_fn &&
87 modify "s/^d/z/" new_fn &&
88 git add new_fn &&
89 git diff -M --cached > patch1 &&
90 git commit -m "a rename" &&
91 git mv other_fn same_fn &&
92 modify "s/^e/y/" same_fn &&
93 git add same_fn &&
94 git diff -M --cached >> patch1 &&
95 modify "s/^g/x/" same_fn &&
96 git diff >> patch1 &&
97 git reset --hard HEAD^ &&
98 git apply patch1
99 '
100
101 test_done