t/gpg: simplify test for unknown key
[git/debian.git] / t / t4127-apply-same-fn.sh
blob305b7e649eb7a123556d89deae0c34ec91265905
1 #!/bin/sh
3 test_description='apply same filename'
5 . ./test-lib.sh
7 modify () {
8 sed -e "$1" < "$2" > "$2".x &&
9 mv "$2".x "$2"
12 test_expect_success setup '
13 for i in a b c d e f g h i j k l m
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
21 test_expect_success 'apply same filename with independent changes' '
22 modify "s/^d/z/" same_fn &&
23 git diff > patch0 &&
24 git add same_fn &&
25 modify "s/^i/y/" same_fn &&
26 git diff >> patch0 &&
27 cp same_fn same_fn2 &&
28 git reset --hard &&
29 git apply patch0 &&
30 test_cmp same_fn same_fn2
33 test_expect_success 'apply same filename with overlapping changes' '
34 git reset --hard &&
36 # Store same_fn so that we can check apply -R in next test
37 cp same_fn same_fn1 &&
39 modify "s/^d/z/" same_fn &&
40 git diff > patch0 &&
41 git add same_fn &&
42 modify "s/^e/y/" same_fn &&
43 git diff >> patch0 &&
44 cp same_fn same_fn2 &&
45 git reset --hard &&
46 git apply patch0 &&
47 test_cmp same_fn same_fn2
50 test_expect_success 'apply same filename with overlapping changes, in reverse' '
51 git apply -R patch0 &&
52 test_cmp same_fn same_fn1
55 test_expect_success 'apply same new filename after rename' '
56 git reset --hard &&
57 git mv same_fn new_fn &&
58 modify "s/^d/z/" new_fn &&
59 git add new_fn &&
60 git diff -M --cached > patch1 &&
61 modify "s/^e/y/" new_fn &&
62 git diff >> patch1 &&
63 cp new_fn new_fn2 &&
64 git reset --hard &&
65 git apply --index patch1 &&
66 test_cmp new_fn new_fn2
69 test_expect_success 'apply same old filename after rename -- should fail.' '
70 git reset --hard &&
71 git mv same_fn new_fn &&
72 modify "s/^d/z/" new_fn &&
73 git add new_fn &&
74 git diff -M --cached > patch1 &&
75 git mv new_fn same_fn &&
76 modify "s/^e/y/" same_fn &&
77 git diff >> patch1 &&
78 git reset --hard &&
79 test_must_fail git apply patch1
82 test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' '
83 git reset --hard &&
84 git mv same_fn new_fn &&
85 modify "s/^d/z/" new_fn &&
86 git add new_fn &&
87 git diff -M --cached > patch1 &&
88 git commit -m "a rename" &&
89 git mv other_fn same_fn &&
90 modify "s/^e/y/" same_fn &&
91 git add same_fn &&
92 git diff -M --cached >> patch1 &&
93 modify "s/^g/x/" same_fn &&
94 git diff >> patch1 &&
95 git reset --hard HEAD^ &&
96 git apply patch1
99 test_done