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