]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2030-unresolve-info.sh
path.c: don't call the match function without value in trie_find()
[thirdparty/git.git] / t / t2030-unresolve-info.sh
CommitLineData
9d9a2f4a
JH
1#!/bin/sh
2
3test_description='undoing resolution'
4
5. ./test-lib.sh
6
7check_resolve_undo () {
8 msg=$1
9 shift
10 while case $# in
11 0) break ;;
12 1|2|3) die "Bug in check-resolve-undo test" ;;
13 esac
14 do
15 path=$1
16 shift
17 for stage in 1 2 3
18 do
19 sha1=$1
20 shift
21 case "$sha1" in
22 '') continue ;;
23 esac
24 sha1=$(git rev-parse --verify "$sha1")
25 printf "100644 %s %s\t%s\n" $sha1 $stage $path
26 done
27 done >"$msg.expect" &&
28 git ls-files --resolve-undo >"$msg.actual" &&
29 test_cmp "$msg.expect" "$msg.actual"
30}
31
32prime_resolve_undo () {
33 git reset --hard &&
34 git checkout second^0 &&
35 test_tick &&
36 test_must_fail git merge third^0 &&
37 echo merge does not leave anything &&
38 check_resolve_undo empty &&
5a9f0395
JS
39 echo different >fi/le &&
40 git add fi/le &&
9d9a2f4a 41 echo resolving records &&
5a9f0395 42 check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
9d9a2f4a
JH
43}
44
45test_expect_success setup '
5a9f0395 46 mkdir fi &&
53d8afaf
JS
47 printf "a\0a" >binary &&
48 git add binary &&
5a9f0395 49 test_commit initial fi/le first &&
9d9a2f4a
JH
50 git branch side &&
51 git branch another &&
53d8afaf
JS
52 printf "a\0b" >binary &&
53 git add binary &&
5a9f0395 54 test_commit second fi/le second &&
9d9a2f4a 55 git checkout side &&
5a9f0395 56 test_commit third fi/le third &&
b9e31f59 57 git branch add-add &&
9d9a2f4a 58 git checkout another &&
5a9f0395 59 test_commit fourth fi/le fourth &&
b9e31f59
JS
60 git checkout add-add &&
61 test_commit fifth add-differently &&
9d9a2f4a
JH
62 git checkout master
63'
64
65test_expect_success 'add records switch clears' '
66 prime_resolve_undo &&
67 test_tick &&
68 git commit -m merged &&
69 echo committing keeps &&
5a9f0395 70 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
9d9a2f4a
JH
71 git checkout second^0 &&
72 echo switching clears &&
73 check_resolve_undo cleared
74'
75
76test_expect_success 'rm records reset clears' '
77 prime_resolve_undo &&
78 test_tick &&
79 git commit -m merged &&
80 echo committing keeps &&
5a9f0395 81 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
9d9a2f4a
JH
82
83 echo merge clears upfront &&
84 test_must_fail git merge fourth^0 &&
85 check_resolve_undo nuked &&
86
5a9f0395 87 git rm -f fi/le &&
9d9a2f4a 88 echo resolving records &&
5a9f0395 89 check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le &&
9d9a2f4a
JH
90
91 git reset --hard &&
92 echo resetting discards &&
93 check_resolve_undo discarded
94'
95
4a39f79d
JH
96test_expect_success 'plumbing clears' '
97 prime_resolve_undo &&
98 test_tick &&
99 git commit -m merged &&
100 echo committing keeps &&
5a9f0395 101 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
4a39f79d
JH
102
103 echo plumbing clear &&
104 git update-index --clear-resolve-undo &&
105 check_resolve_undo cleared
106'
107
4421a823
JH
108test_expect_success 'add records checkout -m undoes' '
109 prime_resolve_undo &&
110 git diff HEAD &&
5a9f0395 111 git checkout --conflict=merge fi/le &&
4421a823
JH
112 echo checkout used the record and removed it &&
113 check_resolve_undo removed &&
114 echo the index and the work tree is unmerged again &&
115 git diff >actual &&
116 grep "^++<<<<<<<" actual
117'
118
8aa38563
JH
119test_expect_success 'unmerge with plumbing' '
120 prime_resolve_undo &&
5a9f0395 121 git update-index --unresolve fi/le &&
8aa38563 122 git ls-files -u >actual &&
3fb0459b 123 test_line_count = 3 actual
8aa38563
JH
124'
125
5a9f0395 126test_expect_success 'rerere and rerere forget' '
dea4562b
JH
127 mkdir .git/rr-cache &&
128 prime_resolve_undo &&
129 echo record the resolution &&
130 git rerere &&
131 rerere_id=$(cd .git/rr-cache && echo */postimage) &&
132 rerere_id=${rerere_id%/postimage} &&
133 test -f .git/rr-cache/$rerere_id/postimage &&
5a9f0395 134 git checkout -m fi/le &&
dea4562b 135 echo resurrect the conflict &&
5a9f0395 136 grep "^=======" fi/le &&
dea4562b
JH
137 echo reresolve the conflict &&
138 git rerere &&
5a9f0395 139 test "z$(cat fi/le)" = zdifferent &&
dea4562b 140 echo register the resolution again &&
5a9f0395
JS
141 git add fi/le &&
142 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
dea4562b 143 test -z "$(git ls-files -u)" &&
5a9f0395 144 git rerere forget fi/le &&
dea4562b
JH
145 ! test -f .git/rr-cache/$rerere_id/postimage &&
146 tr "\0" "\n" <.git/MERGE_RR >actual &&
5a9f0395
JS
147 echo "$rerere_id fi/le" >expect &&
148 test_cmp expect actual
149'
150
151test_expect_success 'rerere and rerere forget (subdirectory)' '
152 rm -fr .git/rr-cache &&
153 mkdir .git/rr-cache &&
154 prime_resolve_undo &&
155 echo record the resolution &&
156 (cd fi && git rerere) &&
157 rerere_id=$(cd .git/rr-cache && echo */postimage) &&
158 rerere_id=${rerere_id%/postimage} &&
159 test -f .git/rr-cache/$rerere_id/postimage &&
160 (cd fi && git checkout -m le) &&
161 echo resurrect the conflict &&
162 grep "^=======" fi/le &&
163 echo reresolve the conflict &&
164 (cd fi && git rerere) &&
165 test "z$(cat fi/le)" = zdifferent &&
166 echo register the resolution again &&
167 (cd fi && git add le) &&
168 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
169 test -z "$(git ls-files -u)" &&
170 (cd fi && git rerere forget le) &&
171 ! test -f .git/rr-cache/$rerere_id/postimage &&
172 tr "\0" "\n" <.git/MERGE_RR >actual &&
173 echo "$rerere_id fi/le" >expect &&
dea4562b
JH
174 test_cmp expect actual
175'
176
53d8afaf
JS
177test_expect_success 'rerere forget (binary)' '
178 git checkout -f side &&
179 printf "a\0c" >binary &&
180 git commit -a -m binary &&
181 test_must_fail git merge second &&
182 git rerere forget binary
183'
184
b9e31f59
JS
185test_expect_success 'rerere forget (add-add conflict)' '
186 git checkout -f master &&
187 echo master >add-differently &&
188 git add add-differently &&
189 git commit -m "add differently" &&
190 test_must_fail git merge fifth &&
191 git rerere forget add-differently 2>actual &&
192 test_i18ngrep "no remembered" actual
193'
194
9d9a2f4a 195test_done