The fifth batch
[git.git] / t / t6404-recursive-merge.sh
blobc7ab7048f589ec506888135960138dd4c11ca282
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-lib.sh
9 # This scenario is based on a real-world repository of Shawn Pearce.
11 # 1 - A - D - F
12 # \ X /
13 # B X
14 # X \
15 # 2 - C - E - G
17 GIT_COMMITTER_DATE="2006-12-12 23:28:00 +0100"
18 export GIT_COMMITTER_DATE
20 test_expect_success 'setup tests' '
21 echo 1 >a1 &&
22 git add a1 &&
23 GIT_AUTHOR_DATE="2006-12-12 23:00:00" git commit -m 1 a1 &&
25 git checkout -b A main &&
26 echo A >a1 &&
27 GIT_AUTHOR_DATE="2006-12-12 23:00:01" git commit -m A a1 &&
29 git checkout -b B main &&
30 echo B >a1 &&
31 GIT_AUTHOR_DATE="2006-12-12 23:00:02" git commit -m B a1 &&
33 git checkout -b D A &&
34 git rev-parse B >.git/MERGE_HEAD &&
35 echo D >a1 &&
36 git update-index a1 &&
37 GIT_AUTHOR_DATE="2006-12-12 23:00:03" git commit -m D &&
39 git symbolic-ref HEAD refs/heads/other &&
40 echo 2 >a1 &&
41 GIT_AUTHOR_DATE="2006-12-12 23:00:04" git commit -m 2 a1 &&
43 git checkout -b C &&
44 echo C >a1 &&
45 GIT_AUTHOR_DATE="2006-12-12 23:00:05" git commit -m C a1 &&
47 git checkout -b E C &&
48 git rev-parse B >.git/MERGE_HEAD &&
49 echo E >a1 &&
50 git update-index a1 &&
51 GIT_AUTHOR_DATE="2006-12-12 23:00:06" git commit -m E &&
53 git checkout -b G E &&
54 git rev-parse A >.git/MERGE_HEAD &&
55 echo G >a1 &&
56 git update-index a1 &&
57 GIT_AUTHOR_DATE="2006-12-12 23:00:07" git commit -m G &&
59 git checkout -b F D &&
60 git rev-parse C >.git/MERGE_HEAD &&
61 echo F >a1 &&
62 git update-index a1 &&
63 GIT_AUTHOR_DATE="2006-12-12 23:00:08" git commit -m F &&
65 test_oid_cache <<-EOF
66 idxstage1 sha1:ec3fe2a791706733f2d8fa7ad45d9a9672031f5e
67 idxstage1 sha256:b3c8488929903aaebdeb22270cb6d36e5b8724b01ae0d4da24632f158c99676f
68 EOF
71 test_expect_success 'combined merge conflicts' '
72 test_must_fail env GIT_TEST_COMMIT_GRAPH=0 git merge -m final G
75 test_expect_success 'result contains a conflict' '
76 cat >expect <<-\EOF &&
77 <<<<<<< HEAD
79 =======
81 >>>>>>> G
82 EOF
84 test_cmp expect a1
87 test_expect_success 'virtual trees were processed' '
88 git ls-files --stage >out &&
90 cat >expect <<-EOF &&
91 100644 $(test_oid idxstage1) 1 a1
92 100644 $(git rev-parse F:a1) 2 a1
93 100644 $(git rev-parse G:a1) 3 a1
94 EOF
96 test_cmp expect out
99 test_expect_success 'refuse to merge binary files' '
100 git reset --hard &&
101 printf "\0" >binary-file &&
102 git add binary-file &&
103 git commit -m binary &&
104 git checkout G &&
105 printf "\0\0" >binary-file &&
106 git add binary-file &&
107 git commit -m binary2 &&
108 test_must_fail git merge F >merge.out 2>merge.err &&
109 grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err
112 test_expect_success 'mark rename/delete as unmerged' '
114 git reset --hard &&
115 git checkout -b delete &&
116 git rm a1 &&
117 test_tick &&
118 git commit -m delete &&
119 git checkout -b rename HEAD^ &&
120 git mv a1 a2 &&
121 test_tick &&
122 git commit -m rename &&
123 test_must_fail git merge delete &&
124 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
125 then
126 test 2 = $(git ls-files --unmerged | wc -l)
127 else
128 test 1 = $(git ls-files --unmerged | wc -l)
129 fi &&
130 git rev-parse --verify :2:a2 &&
131 test_must_fail git rev-parse --verify :3:a2 &&
132 git checkout -f delete &&
133 test_must_fail git merge rename &&
134 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
135 then
136 test 2 = $(git ls-files --unmerged | wc -l)
137 else
138 test 1 = $(git ls-files --unmerged | wc -l)
139 fi &&
140 test_must_fail git rev-parse --verify :2:a2 &&
141 git rev-parse --verify :3:a2
144 test_done