blob: 3de4ef6bd9e640d2f82deb111dd307e9a000db91 [file] [log] [blame]
Fredrik Kuivinen72d12162005-12-03 11:41:20 +01001#!/bin/sh
2#
3# Copyright (c) 2005 Fredrik Kuivinen
4#
5
6test_description='Test merge with directory/file conflicts'
Johannes Schindelin5902f5f2020-11-18 23:44:38 +00007GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00008export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
Fredrik Kuivinen72d12162005-12-03 11:41:20 +010010. ./test-lib.sh
11
Elijah Newrend09c0a32010-09-20 02:28:42 -060012test_expect_success 'prepare repository' '
13 echo Hello >init &&
14 git add init &&
15 git commit -m initial &&
Fredrik Kuivinen72d12162005-12-03 11:41:20 +010016
Elijah Newrend09c0a32010-09-20 02:28:42 -060017 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'
Fredrik Kuivinen72d12162005-12-03 11:41:20 +010028
Ævar Arnfjörð Bjarmason892e6f72010-10-03 13:59:59 -060029test_expect_success 'Merge with d/f conflicts' '
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000030 test_expect_code 1 git merge -m "merge msg" main
Ævar Arnfjörð Bjarmason892e6f72010-10-03 13:59:59 -060031'
Fredrik Kuivinen72d12162005-12-03 11:41:20 +010032
Elijah Newren5a2580d2010-07-09 07:10:54 -060033test_expect_success 'F/D conflict' '
Alex Riesen1c9b2d32009-05-11 11:31:42 +020034 git reset --hard &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000035 git checkout main &&
Alex Riesen1c9b2d32009-05-11 11:31:42 +020036 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
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000053 git merge main
Alex Riesen1c9b2d32009-05-11 11:31:42 +020054'
55
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060056test_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
Elijah Newrenf0fd4d02011-08-11 23:19:56 -060065 # Throw in letters.txt for sorting order fun
66 # ("letters.txt" sorts between "letters" and "letters/file")
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060067 echo i >>letters &&
Elijah Newrenf0fd4d02011-08-11 23:19:56 -060068 echo "version 2" >letters.txt &&
69 git add letters letters.txt &&
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060070 git commit -m modified &&
71
72 git checkout -b delete HEAD^ &&
73 git rm letters &&
74 mkdir letters &&
75 >letters/file &&
Elijah Newrenf0fd4d02011-08-11 23:19:56 -060076 echo "version 1" >letters.txt &&
77 git add letters letters.txt &&
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060078 git commit -m deleted
79'
80
Elijah Newren84a08a42010-09-20 02:29:08 -060081test_expect_success 'modify/delete + directory/file conflict' '
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060082 git checkout delete^0 &&
83 test_must_fail git merge modify &&
84
Đoàn Trần Công Danh66c95622021-07-04 12:46:11 +070085 test_stdout_line_count = 5 git ls-files -s &&
86 test_stdout_line_count = 4 git ls-files -u &&
Elijah Newrenef527782020-10-26 17:01:37 +000087 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
88 then
Đoàn Trần Công Danh66c95622021-07-04 12:46:11 +070089 test_stdout_line_count = 0 git ls-files -o
Elijah Newrenef527782020-10-26 17:01:37 +000090 else
Đoàn Trần Công Danh66c95622021-07-04 12:46:11 +070091 test_stdout_line_count = 1 git ls-files -o
Elijah Newrenef527782020-10-26 17:01:37 +000092 fi &&
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060093
Elijah Newrenb821ca72020-02-27 00:14:21 +000094 test_path_is_file letters/file &&
95 test_path_is_file letters.txt &&
96 test_path_is_file letters~modify
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -060097'
98
Elijah Newrenef02b312010-09-20 02:29:09 -060099test_expect_success 'modify/delete + directory/file conflict; other way' '
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -0600100 git reset --hard &&
101 git clean -f &&
102 git checkout modify^0 &&
Elijah Newrenf0fd4d02011-08-11 23:19:56 -0600103
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -0600104 test_must_fail git merge delete &&
105
Đoàn Trần Công Danh66c95622021-07-04 12:46:11 +0700106 test_stdout_line_count = 5 git ls-files -s &&
107 test_stdout_line_count = 4 git ls-files -u &&
Elijah Newrenef527782020-10-26 17:01:37 +0000108 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
109 then
Đoàn Trần Công Danh66c95622021-07-04 12:46:11 +0700110 test_stdout_line_count = 0 git ls-files -o
Elijah Newrenef527782020-10-26 17:01:37 +0000111 else
Đoàn Trần Công Danh66c95622021-07-04 12:46:11 +0700112 test_stdout_line_count = 1 git ls-files -o
Elijah Newrenef527782020-10-26 17:01:37 +0000113 fi &&
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -0600114
Elijah Newrenb821ca72020-02-27 00:14:21 +0000115 test_path_is_file letters/file &&
116 test_path_is_file letters.txt &&
117 test_path_is_file letters~HEAD
Elijah Newrenfa0ae3b2010-09-20 02:28:43 -0600118'
119
Elijah Newren65bf8202020-02-27 00:14:24 +0000120test_expect_success 'Simple merge in repo with interesting pathnames' '
121 # Simple lexicographic ordering of files and directories would be:
122 # foo
123 # foo/bar
124 # foo/bar-2
125 # foo/bar/baz
126 # foo/bar-2/baz
127 # The fact that foo/bar-2 appears between foo/bar and foo/bar/baz
128 # can trip up some codepaths, and is the point of this test.
Elijah Newren6693fb32022-08-26 03:49:19 +0000129 git init name-ordering &&
Elijah Newren65bf8202020-02-27 00:14:24 +0000130 (
131 cd name-ordering &&
132
133 mkdir -p foo/bar &&
134 mkdir -p foo/bar-2 &&
135 >foo/bar/baz &&
136 >foo/bar-2/baz &&
137 git add . &&
138 git commit -m initial &&
139
Johannes Schindelin538228e2020-10-08 10:13:47 +0000140 git branch topic &&
Elijah Newren65bf8202020-02-27 00:14:24 +0000141 git branch other &&
142
143 git checkout other &&
144 echo other >foo/bar-2/baz &&
145 git add -u &&
146 git commit -m other &&
147
Johannes Schindelin538228e2020-10-08 10:13:47 +0000148 git checkout topic &&
149 echo topic >foo/bar/baz &&
Elijah Newren65bf8202020-02-27 00:14:24 +0000150 git add -u &&
Johannes Schindelin538228e2020-10-08 10:13:47 +0000151 git commit -m topic &&
Elijah Newren65bf8202020-02-27 00:14:24 +0000152
153 git merge other &&
154 git ls-files -s >out &&
155 test_line_count = 2 out &&
156 git rev-parse :0:foo/bar/baz :0:foo/bar-2/baz >actual &&
157 git rev-parse HEAD~1:foo/bar/baz other:foo/bar-2/baz >expect &&
158 test_cmp expect actual
159 )
160
161'
162
Fredrik Kuivinen72d12162005-12-03 11:41:20 +0100163test_done