Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Fredrik Kuivinen
4 #
5
6 test_description='Test merge with directory/file conflicts'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10 . ./test-lib.sh
11
12 test_expect_success 'prepare repository' '
13 echo Hello >init &&
14 git add init &&
15 git commit -m initial &&
16
17 git branch B &&
18 mkdir dir &&
19 echo foo >dir/foo &&
20 git add dir/foo &&
21 git commit -m "File: dir/foo" &&
22
23 git checkout B &&
24 echo file dir >dir &&
25 git add dir &&
26 git commit -m "File: dir"
27 '
28
29 test_expect_success 'Merge with d/f conflicts' '
30 test_expect_code 1 git merge -m "merge msg" main
31 '
32
33 test_expect_success 'F/D conflict' '
34 git reset --hard &&
35 git checkout main &&
36 rm .git/index &&
37
38 mkdir before &&
39 echo FILE >before/one &&
40 echo FILE >after &&
41 git add . &&
42 git commit -m first &&
43
44 rm -f after &&
45 git mv before after &&
46 git commit -m move &&
47
48 git checkout -b para HEAD^ &&
49 echo COMPLETELY ANOTHER FILE >another &&
50 git add . &&
51 git commit -m para &&
52
53 git merge main
54 '
55
56 test_expect_success 'setup modify/delete + directory/file conflict' '
57 git checkout --orphan modify &&
58 git rm -rf . &&
59 git clean -fdqx &&
60
61 printf "a\nb\nc\nd\ne\nf\ng\nh\n" >letters &&
62 git add letters &&
63 git commit -m initial &&
64
65 # Throw in letters.txt for sorting order fun
66 # ("letters.txt" sorts between "letters" and "letters/file")
67 echo i >>letters &&
68 echo "version 2" >letters.txt &&
69 git add letters letters.txt &&
70 git commit -m modified &&
71
72 git checkout -b delete HEAD^ &&
73 git rm letters &&
74 mkdir letters &&
75 >letters/file &&
76 echo "version 1" >letters.txt &&
77 git add letters letters.txt &&
78 git commit -m deleted
79 '
80
81 test_expect_success 'modify/delete + directory/file conflict' '
82 git checkout delete^0 &&
83 test_must_fail git merge modify &&
84
85 test_stdout_line_count = 5 git ls-files -s &&
86 test_stdout_line_count = 4 git ls-files -u &&
87 test_stdout_line_count = 0 git ls-files -o &&
88
89 test_path_is_file letters/file &&
90 test_path_is_file letters.txt &&
91 test_path_is_file letters~modify
92 '
93
94 test_expect_success 'modify/delete + directory/file conflict; other way' '
95 git reset --hard &&
96 git clean -f &&
97 git checkout modify^0 &&
98
99 test_must_fail git merge delete &&
100
101 test_stdout_line_count = 5 git ls-files -s &&
102 test_stdout_line_count = 4 git ls-files -u &&
103 test_stdout_line_count = 0 git ls-files -o &&
104
105 test_path_is_file letters/file &&
106 test_path_is_file letters.txt &&
107 test_path_is_file letters~HEAD
108 '
109
110 test_expect_success 'Simple merge in repo with interesting pathnames' '
111 # Simple lexicographic ordering of files and directories would be:
112 # foo
113 # foo/bar
114 # foo/bar-2
115 # foo/bar/baz
116 # foo/bar-2/baz
117 # The fact that foo/bar-2 appears between foo/bar and foo/bar/baz
118 # can trip up some codepaths, and is the point of this test.
119 git init name-ordering &&
120 (
121 cd name-ordering &&
122
123 mkdir -p foo/bar &&
124 mkdir -p foo/bar-2 &&
125 >foo/bar/baz &&
126 >foo/bar-2/baz &&
127 git add . &&
128 git commit -m initial &&
129
130 git branch topic &&
131 git branch other &&
132
133 git checkout other &&
134 echo other >foo/bar-2/baz &&
135 git add -u &&
136 git commit -m other &&
137
138 git checkout topic &&
139 echo topic >foo/bar/baz &&
140 git add -u &&
141 git commit -m topic &&
142
143 git merge other &&
144 git ls-files -s >out &&
145 test_line_count = 2 out &&
146 git rev-parse :0:foo/bar/baz :0:foo/bar-2/baz >actual &&
147 git rev-parse HEAD~1:foo/bar/baz other:foo/bar-2/baz >expect &&
148 test_cmp expect actual
149 )
150
151 '
152
153 test_done