]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6404-recursive-merge.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t6404-recursive-merge.sh
1 #!/bin/sh
2
3 test_description='Test merge without common ancestors'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 . ./test-lib.sh
8
9 # This scenario is based on a real-world repository of Shawn Pearce.
10
11 # 1 - A - D - F
12 # \ X /
13 # B X
14 # X \
15 # 2 - C - E - G
16
17 GIT_COMMITTER_DATE="2006-12-12 23:28:00 +0100"
18 export GIT_COMMITTER_DATE
19
20 test_expect_success 'setup tests' '
21 GIT_TEST_COMMIT_GRAPH=0 &&
22 export GIT_TEST_COMMIT_GRAPH &&
23 echo 1 >a1 &&
24 git add a1 &&
25 GIT_AUTHOR_DATE="2006-12-12 23:00:00" git commit -m 1 a1 &&
26
27 git checkout -b A main &&
28 echo A >a1 &&
29 GIT_AUTHOR_DATE="2006-12-12 23:00:01" git commit -m A a1 &&
30
31 git checkout -b B main &&
32 echo B >a1 &&
33 GIT_AUTHOR_DATE="2006-12-12 23:00:02" git commit -m B a1 &&
34
35 git checkout -b D A &&
36 git rev-parse B >.git/MERGE_HEAD &&
37 echo D >a1 &&
38 git update-index a1 &&
39 GIT_AUTHOR_DATE="2006-12-12 23:00:03" git commit -m D &&
40
41 git symbolic-ref HEAD refs/heads/other &&
42 echo 2 >a1 &&
43 GIT_AUTHOR_DATE="2006-12-12 23:00:04" git commit -m 2 a1 &&
44
45 git checkout -b C &&
46 echo C >a1 &&
47 GIT_AUTHOR_DATE="2006-12-12 23:00:05" git commit -m C a1 &&
48
49 git checkout -b E C &&
50 git rev-parse B >.git/MERGE_HEAD &&
51 echo E >a1 &&
52 git update-index a1 &&
53 GIT_AUTHOR_DATE="2006-12-12 23:00:06" git commit -m E &&
54
55 git checkout -b G E &&
56 git rev-parse A >.git/MERGE_HEAD &&
57 echo G >a1 &&
58 git update-index a1 &&
59 GIT_AUTHOR_DATE="2006-12-12 23:00:07" git commit -m G &&
60
61 git checkout -b F D &&
62 git rev-parse C >.git/MERGE_HEAD &&
63 echo F >a1 &&
64 git update-index a1 &&
65 GIT_AUTHOR_DATE="2006-12-12 23:00:08" git commit -m F &&
66
67 test_oid_cache <<-EOF
68 idxstage1 sha1:ec3fe2a791706733f2d8fa7ad45d9a9672031f5e
69 idxstage1 sha256:b3c8488929903aaebdeb22270cb6d36e5b8724b01ae0d4da24632f158c99676f
70 EOF
71 '
72
73 test_expect_success 'combined merge conflicts' '
74 test_must_fail git merge -m final G
75 '
76
77 test_expect_success 'result contains a conflict' '
78 cat >expect <<-\EOF &&
79 <<<<<<< HEAD
80 F
81 =======
82 G
83 >>>>>>> G
84 EOF
85
86 test_cmp expect a1
87 '
88
89 test_expect_success 'virtual trees were processed' '
90 # TODO: fragile test, relies on ambigious merge-base resolution
91 git ls-files --stage >out &&
92
93 cat >expect <<-EOF &&
94 100644 $(test_oid idxstage1) 1 a1
95 100644 $(git rev-parse F:a1) 2 a1
96 100644 $(git rev-parse G:a1) 3 a1
97 EOF
98
99 test_cmp expect out
100 '
101
102 test_expect_success 'refuse to merge binary files' '
103 git reset --hard &&
104 printf "\0" >binary-file &&
105 git add binary-file &&
106 git commit -m binary &&
107 git checkout G &&
108 printf "\0\0" >binary-file &&
109 git add binary-file &&
110 git commit -m binary2 &&
111 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
112 then
113 test_must_fail git merge F >merge_output
114 else
115 test_must_fail git merge F 2>merge_output
116 fi &&
117 grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge_output
118 '
119
120 test_expect_success 'mark rename/delete as unmerged' '
121
122 git reset --hard &&
123 git checkout -b delete &&
124 git rm a1 &&
125 test_tick &&
126 git commit -m delete &&
127 git checkout -b rename HEAD^ &&
128 git mv a1 a2 &&
129 test_tick &&
130 git commit -m rename &&
131 test_must_fail git merge delete &&
132 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
133 then
134 test 2 = $(git ls-files --unmerged | wc -l)
135 else
136 test 1 = $(git ls-files --unmerged | wc -l)
137 fi &&
138 git rev-parse --verify :2:a2 &&
139 test_must_fail git rev-parse --verify :3:a2 &&
140 git checkout -f delete &&
141 test_must_fail git merge rename &&
142 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
143 then
144 test 2 = $(git ls-files --unmerged | wc -l)
145 else
146 test 1 = $(git ls-files --unmerged | wc -l)
147 fi &&
148 test_must_fail git rev-parse --verify :2:a2 &&
149 git rev-parse --verify :3:a2
150 '
151
152 test_done