]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4127-apply-same-fn.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t4127-apply-same-fn.sh
CommitLineData
7a07841c
DZ
1#!/bin/sh
2
3test_description='apply same filename'
4
f54f48fc
ÆAB
5
6TEST_PASSES_SANITIZE_LEAK=true
7a07841c
DZ
7. ./test-lib.sh
8
41872fd5
JS
9modify () {
10 sed -e "$1" < "$2" > "$2".x &&
11 mv "$2".x "$2"
12}
13
7a07841c 14test_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'
20test_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
32test_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
49test_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 54test_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
68test_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
81test_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
98test_done