clone_submodule: avoid using `access()` on directories
[git.git] / t / t4127-apply-same-fn.sh
blobaa5cfae2b681c0a73d9e09493c8cdcbb6a273f87
1 #!/bin/sh
3 test_description='apply same filename'
6 TEST_PASSES_SANITIZE_LEAK=true
7 . ./test-lib.sh
9 modify () {
10 sed -e "$1" < "$2" > "$2".x &&
11 mv "$2".x "$2"
14 test_expect_success setup '
15 test_write_lines a b c d e f g h i j k l m >same_fn &&
16 cp same_fn other_fn &&
17 git add same_fn other_fn &&
18 git commit -m initial
20 test_expect_success 'apply same filename with independent changes' '
21 modify "s/^d/z/" same_fn &&
22 git diff > patch0 &&
23 git add same_fn &&
24 modify "s/^i/y/" same_fn &&
25 git diff >> patch0 &&
26 cp same_fn same_fn2 &&
27 git reset --hard &&
28 git apply patch0 &&
29 test_cmp same_fn same_fn2
32 test_expect_success 'apply same filename with overlapping changes' '
33 git reset --hard &&
35 # Store same_fn so that we can check apply -R in next test
36 cp same_fn same_fn1 &&
38 modify "s/^d/z/" same_fn &&
39 git diff > patch0 &&
40 git add same_fn &&
41 modify "s/^e/y/" same_fn &&
42 git diff >> patch0 &&
43 cp same_fn same_fn2 &&
44 git reset --hard &&
45 git apply patch0 &&
46 test_cmp same_fn same_fn2
49 test_expect_success 'apply same filename with overlapping changes, in reverse' '
50 git apply -R patch0 &&
51 test_cmp same_fn same_fn1
54 test_expect_success 'apply same new filename after rename' '
55 git reset --hard &&
56 git mv same_fn new_fn &&
57 modify "s/^d/z/" new_fn &&
58 git add new_fn &&
59 git diff -M --cached > patch1 &&
60 modify "s/^e/y/" new_fn &&
61 git diff >> patch1 &&
62 cp new_fn new_fn2 &&
63 git reset --hard &&
64 git apply --index patch1 &&
65 test_cmp new_fn new_fn2
68 test_expect_success 'apply same old filename after rename -- should fail.' '
69 git reset --hard &&
70 git mv same_fn new_fn &&
71 modify "s/^d/z/" new_fn &&
72 git add new_fn &&
73 git diff -M --cached > patch1 &&
74 git mv new_fn same_fn &&
75 modify "s/^e/y/" same_fn &&
76 git diff >> patch1 &&
77 git reset --hard &&
78 test_must_fail git apply patch1
81 test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' '
82 git reset --hard &&
83 git mv same_fn new_fn &&
84 modify "s/^d/z/" new_fn &&
85 git add new_fn &&
86 git diff -M --cached > patch1 &&
87 git commit -m "a rename" &&
88 git mv other_fn same_fn &&
89 modify "s/^e/y/" same_fn &&
90 git add same_fn &&
91 git diff -M --cached >> patch1 &&
92 modify "s/^g/x/" same_fn &&
93 git diff >> patch1 &&
94 git reset --hard HEAD^ &&
95 git apply patch1
98 test_done