]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4301-merge-tree-write-tree.sh
merge-ort: optionally produce machine-readable output
[thirdparty/git.git] / t / t4301-merge-tree-write-tree.sh
CommitLineData
1f0c3a29
EN
1#!/bin/sh
2
3test_description='git merge-tree --write-tree'
4
5. ./test-lib.sh
6
7# This test is ort-specific
8if test "$GIT_TEST_MERGE_ALGORITHM" != "ort"
9then
10 skip_all="GIT_TEST_MERGE_ALGORITHM != ort"
11 test_done
12fi
13
14test_expect_success setup '
15 test_write_lines 1 2 3 4 5 >numbers &&
16 echo hello >greeting &&
17 echo foo >whatever &&
18 git add numbers greeting whatever &&
19 test_tick &&
20 git commit -m initial &&
21
22 git branch side1 &&
23 git branch side2 &&
24 git branch side3 &&
25
26 git checkout side1 &&
27 test_write_lines 1 2 3 4 5 6 >numbers &&
28 echo hi >greeting &&
29 echo bar >whatever &&
30 git add numbers greeting whatever &&
31 test_tick &&
32 git commit -m modify-stuff &&
33
34 git checkout side2 &&
35 test_write_lines 0 1 2 3 4 5 >numbers &&
36 echo yo >greeting &&
37 git rm whatever &&
38 mkdir whatever &&
39 >whatever/empty &&
40 git add numbers greeting whatever/empty &&
41 test_tick &&
42 git commit -m other-modifications &&
43
44 git checkout side3 &&
45 git mv numbers sequence &&
46 test_tick &&
47 git commit -m rename-numbers
48'
49
50test_expect_success 'Clean merge' '
51 TREE_OID=$(git merge-tree --write-tree side1 side3) &&
52 q_to_tab <<-EOF >expect &&
53 100644 blob $(git rev-parse side1:greeting)Qgreeting
54 100644 blob $(git rev-parse side1:numbers)Qsequence
55 100644 blob $(git rev-parse side1:whatever)Qwhatever
56 EOF
57
58 git ls-tree $TREE_OID >actual &&
59 test_cmp expect actual
60'
61
62test_expect_success 'Content merge and a few conflicts' '
63 git checkout side1^0 &&
64 test_must_fail git merge side2 &&
65 expected_tree=$(git rev-parse AUTO_MERGE) &&
66
67 # We will redo the merge, while we are still in a conflicted state!
b520bc6c 68 git ls-files -u >conflicted-file-info &&
1f0c3a29
EN
69 test_when_finished "git reset --hard" &&
70
71 test_expect_code 1 git merge-tree --write-tree side1 side2 >RESULT &&
72 actual_tree=$(head -n 1 RESULT) &&
73
74 # Due to differences of e.g. "HEAD" vs "side1", the results will not
75 # exactly match. Dig into individual files.
76
77 # Numbers should have three-way merged cleanly
78 test_write_lines 0 1 2 3 4 5 6 >expect &&
79 git show ${actual_tree}:numbers >actual &&
80 test_cmp expect actual &&
81
82 # whatever and whatever~<branch> should have same HASHES
83 git rev-parse ${expected_tree}:whatever ${expected_tree}:whatever~HEAD >expect &&
84 git rev-parse ${actual_tree}:whatever ${actual_tree}:whatever~side1 >actual &&
85 test_cmp expect actual &&
86
87 # greeting should have a merge conflict
88 git show ${expected_tree}:greeting >tmp &&
89 sed -e s/HEAD/side1/ tmp >expect &&
90 git show ${actual_tree}:greeting >actual &&
91 test_cmp expect actual
92'
93
94test_expect_success 'Barf on misspelled option, with exit code other than 0 or 1' '
95 # Mis-spell with single "s" instead of double "s"
96 test_expect_code 129 git merge-tree --write-tree --mesages FOOBAR side1 side2 2>expect &&
97
98 grep "error: unknown option.*mesages" expect
99'
100
101test_expect_success 'Barf on too many arguments' '
102 test_expect_code 129 git merge-tree --write-tree side1 side2 invalid 2>expect &&
103
104 grep "^usage: git merge-tree" expect
105'
106
a1a78119
EN
107anonymize_hash() {
108 sed -e "s/[0-9a-f]\{40,\}/HASH/g" "$@"
109}
110
111test_expect_success 'test conflict notices and such' '
b520bc6c 112 test_expect_code 1 git merge-tree --write-tree --name-only side1 side2 >out &&
a1a78119
EN
113 anonymize_hash out >actual &&
114
115 # Expected results:
116 # "greeting" should merge with conflicts
117 # "numbers" should merge cleanly
118 # "whatever" has *both* a modify/delete and a file/directory conflict
119 cat <<-EOF >expect &&
120 HASH
7fa33388
EN
121 greeting
122 whatever~side1
a1a78119
EN
123
124 Auto-merging greeting
125 CONFLICT (content): Merge conflict in greeting
126 Auto-merging numbers
127 CONFLICT (file/directory): directory in the way of whatever from side1; moving it to whatever~side1 instead.
128 CONFLICT (modify/delete): whatever~side1 deleted in side2 and modified in side1. Version side1 of whatever~side1 left in tree.
129 EOF
130
131 test_cmp expect actual
132'
133
134for opt in $(git merge-tree --git-completion-helper-all)
135do
136 if test $opt = "--trivial-merge" || test $opt = "--write-tree"
137 then
138 continue
139 fi
140
141 test_expect_success "usage: --trivial-merge is incompatible with $opt" '
142 test_expect_code 128 git merge-tree --trivial-merge $opt side1 side2 side3
143 '
144done
145
7fa33388 146test_expect_success 'Just the conflicted files without the messages' '
b520bc6c 147 test_expect_code 1 git merge-tree --write-tree --no-messages --name-only side1 side2 >out &&
7fa33388
EN
148 anonymize_hash out >actual &&
149
150 test_write_lines HASH greeting whatever~side1 >expect &&
151
152 test_cmp expect actual
153'
154
b520bc6c
EN
155test_expect_success 'Check conflicted oids and modes without messages' '
156 test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out &&
157 anonymize_hash out >actual &&
158
159 # Compare the basic output format
160 q_to_tab >expect <<-\EOF &&
161 HASH
162 100644 HASH 1Qgreeting
163 100644 HASH 2Qgreeting
164 100644 HASH 3Qgreeting
165 100644 HASH 1Qwhatever~side1
166 100644 HASH 2Qwhatever~side1
167 EOF
168
169 test_cmp expect actual &&
170
171 # Check the actual hashes against the `ls-files -u` output too
172 tail -n +2 out | sed -e s/side1/HEAD/ >actual &&
173 test_cmp conflicted-file-info actual
174'
175
1f0c3a29 176test_done