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