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