3 test_description='undoing resolution'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 check_resolve_undo () {
15 1|2|3) die "Bug in check-resolve-undo test" ;;
27 sha1=$(git rev-parse --verify "$sha1")
28 printf "100644 %s %s\t%s\n" $sha1 $stage $path
30 done >"$msg.expect" &&
31 git ls-files --resolve-undo >"$msg.actual" &&
32 test_cmp "$msg.expect" "$msg.actual"
35 prime_resolve_undo () {
37 git checkout second^0 &&
39 test_must_fail git merge third^0 &&
40 echo merge does not leave anything &&
41 check_resolve_undo empty &&
42 echo different >fi/le &&
44 echo resolving records &&
45 check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
48 test_expect_success setup '
50 printf "a\0a" >binary &&
52 test_commit initial fi/le first &&
55 printf "a\0b" >binary &&
57 test_commit second fi/le second &&
59 test_commit third fi/le third &&
61 git checkout another &&
62 test_commit fourth fi/le fourth &&
63 git checkout add-add &&
64 test_commit fifth add-differently &&
68 test_expect_success 'add records switch clears' '
71 git commit -m merged &&
72 echo committing keeps &&
73 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
74 git checkout second^0 &&
75 echo switching clears &&
76 check_resolve_undo cleared
79 test_expect_success 'rm records reset clears' '
82 git commit -m merged &&
83 echo committing keeps &&
84 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
86 echo merge clears upfront &&
87 test_must_fail git merge fourth^0 &&
88 check_resolve_undo nuked &&
91 echo resolving records &&
92 check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le &&
95 echo resetting discards &&
96 check_resolve_undo discarded
99 test_expect_success 'plumbing clears' '
100 prime_resolve_undo &&
102 git commit -m merged &&
103 echo committing keeps &&
104 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
106 echo plumbing clear &&
107 git update-index --clear-resolve-undo &&
108 check_resolve_undo cleared
111 test_expect_success 'add records checkout -m undoes' '
112 prime_resolve_undo &&
114 git checkout --conflict=merge fi/le &&
115 echo checkout used the record and removed it &&
116 check_resolve_undo removed &&
117 echo the index and the work tree is unmerged again &&
119 grep "^++<<<<<<<" actual
122 test_expect_success 'unmerge with plumbing' '
123 prime_resolve_undo &&
124 git update-index --unresolve fi/le &&
125 git ls-files -u >actual &&
126 test_line_count = 3 actual
129 test_expect_success 'rerere and rerere forget' '
130 mkdir .git/rr-cache &&
131 prime_resolve_undo &&
132 echo record the resolution &&
134 rerere_id=$(cd .git/rr-cache && echo */postimage) &&
135 rerere_id=${rerere_id%/postimage} &&
136 test -f .git/rr-cache/$rerere_id/postimage &&
137 git checkout -m fi/le &&
138 echo resurrect the conflict &&
139 grep "^=======" fi/le &&
140 echo reresolve the conflict &&
142 test "z$(cat fi/le)" = zdifferent &&
143 echo register the resolution again &&
145 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
146 test -z "$(git ls-files -u)" &&
147 git rerere forget fi/le &&
148 ! test -f .git/rr-cache/$rerere_id/postimage &&
149 tr "\0" "\n" <.git/MERGE_RR >actual &&
150 echo "$rerere_id fi/le" >expect &&
151 test_cmp expect actual
154 test_expect_success 'rerere and rerere forget (subdirectory)' '
155 rm -fr .git/rr-cache &&
156 mkdir .git/rr-cache &&
157 prime_resolve_undo &&
158 echo record the resolution &&
159 (cd fi && git rerere) &&
160 rerere_id=$(cd .git/rr-cache && echo */postimage) &&
161 rerere_id=${rerere_id%/postimage} &&
162 test -f .git/rr-cache/$rerere_id/postimage &&
163 (cd fi && git checkout -m le) &&
164 echo resurrect the conflict &&
165 grep "^=======" fi/le &&
166 echo reresolve the conflict &&
167 (cd fi && git rerere) &&
168 test "z$(cat fi/le)" = zdifferent &&
169 echo register the resolution again &&
170 (cd fi && git add le) &&
171 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
172 test -z "$(git ls-files -u)" &&
173 (cd fi && git rerere forget le) &&
174 ! test -f .git/rr-cache/$rerere_id/postimage &&
175 tr "\0" "\n" <.git/MERGE_RR >actual &&
176 echo "$rerere_id fi/le" >expect &&
177 test_cmp expect actual
180 test_expect_success 'rerere forget (binary)' '
181 git checkout -f side &&
182 printf "a\0c" >binary &&
183 git commit -a -m binary &&
184 test_must_fail git merge second &&
185 git rerere forget binary
188 test_expect_success 'rerere forget (add-add conflict)' '
189 git checkout -f main &&
190 echo main >add-differently &&
191 git add add-differently &&
192 git commit -m "add differently" &&
193 test_must_fail git merge fifth &&
194 git rerere forget add-differently 2>actual &&
195 test_i18ngrep "no remembered" actual