1#!/bin/sh
2
3test_description='apply same filename'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8 for i in a b c d e f g h i j k l m
9 do
10 echo $i
11 done >same_fn &&
12 cp same_fn other_fn &&
13 git add same_fn other_fn &&
14 git commit -m initial
15'
16test_expect_success 'apply same filename with independent changes' '
17 sed -i -e "s/^d/z/" same_fn &&
18 git diff > patch0 &&
19 git add same_fn &&
20 sed -i -e "s/^i/y/" same_fn &&
21 git diff >> patch0 &&
22 cp same_fn same_fn2 &&
23 git reset --hard &&
24 git-apply patch0 &&
25 diff same_fn same_fn2
26'
27
28test_expect_success 'apply same filename with overlapping changes' '
29 git reset --hard
30 sed -i -e "s/^d/z/" same_fn &&
31 git diff > patch0 &&
32 git add same_fn &&
33 sed -i -e "s/^e/y/" same_fn &&
34 git diff >> patch0 &&
35 cp same_fn same_fn2 &&
36 git reset --hard &&
37 git-apply patch0 &&
38 diff same_fn same_fn2
39'
40
41test_expect_success 'apply same new filename after rename' '
42 git reset --hard
43 git mv same_fn new_fn
44 sed -i -e "s/^d/z/" new_fn &&
45 git add new_fn &&
46 git diff -M --cached > patch1 &&
47 sed -i -e "s/^e/y/" new_fn &&
48 git diff >> patch1 &&
49 cp new_fn new_fn2 &&
50 git reset --hard &&
51 git apply --index patch1 &&
52 diff new_fn new_fn2
53'
54
55test_expect_success 'apply same old filename after rename -- should fail.' '
56 git reset --hard
57 git mv same_fn new_fn
58 sed -i -e "s/^d/z/" new_fn &&
59 git add new_fn &&
60 git diff -M --cached > patch1 &&
61 git mv new_fn same_fn
62 sed -i -e "s/^e/y/" same_fn &&
63 git diff >> patch1 &&
64 git reset --hard &&
65 test_must_fail git apply patch1
66'
67
68test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' '
69 git reset --hard
70 git mv same_fn new_fn
71 sed -i -e "s/^d/z/" new_fn &&
72 git add new_fn &&
73 git diff -M --cached > patch1 &&
74 git commit -m "a rename" &&
75 git mv other_fn same_fn
76 sed -i -e "s/^e/y/" same_fn &&
77 git add same_fn &&
78 git diff -M --cached >> patch1 &&
79 sed -i -e "s/^g/x/" same_fn &&
80 git diff >> patch1 &&
81 git reset --hard HEAD^ &&
82 git apply patch1
83'
84
85test_done