3 test_description
='undoing resolution'
7 check_resolve_undo
() {
12 1|
2|
3) die
"Bug in check-resolve-undo test" ;;
24 sha1
=$
(git rev-parse
--verify "$sha1")
25 printf "100644 %s %s\t%s\n" $sha1 $stage $path
27 done >"$msg.expect" &&
28 git ls-files
--resolve-undo >"$msg.actual" &&
29 test_cmp
"$msg.expect" "$msg.actual"
32 prime_resolve_undo
() {
34 git checkout second^
0 &&
36 test_must_fail git merge third^
0 &&
37 echo merge does not leave anything
&&
38 check_resolve_undo empty
&&
39 echo different
>fi
/le
&&
41 echo resolving records
&&
42 check_resolve_undo recorded fi
/le initial
:fi
/le second
:fi
/le third
:fi
/le
45 test_expect_success setup
'
47 printf "a\0a" >binary &&
49 test_commit initial fi/le first &&
52 printf "a\0b" >binary &&
54 test_commit second fi/le second &&
56 test_commit third fi/le third &&
58 git checkout another &&
59 test_commit fourth fi/le fourth &&
60 git checkout add-add &&
61 test_commit fifth add-differently &&
65 test_expect_success
'add records switch clears' '
68 git commit -m merged &&
69 echo committing keeps &&
70 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
71 git checkout second^0 &&
72 echo switching clears &&
73 check_resolve_undo cleared
76 test_expect_success
'rm records reset clears' '
79 git commit -m merged &&
80 echo committing keeps &&
81 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
83 echo merge clears upfront &&
84 test_must_fail git merge fourth^0 &&
85 check_resolve_undo nuked &&
88 echo resolving records &&
89 check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le &&
92 echo resetting discards &&
93 check_resolve_undo discarded
96 test_expect_success
'plumbing clears' '
99 git commit -m merged &&
100 echo committing keeps &&
101 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
103 echo plumbing clear &&
104 git update-index --clear-resolve-undo &&
105 check_resolve_undo cleared
108 test_expect_success
'add records checkout -m undoes' '
109 prime_resolve_undo &&
111 git checkout --conflict=merge fi/le &&
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 &&
116 grep "^++<<<<<<<" actual
119 test_expect_success
'unmerge with plumbing' '
120 prime_resolve_undo &&
121 git update-index --unresolve fi/le &&
122 git ls-files -u >actual &&
123 test_line_count = 3 actual
126 test_expect_success
'rerere and rerere forget' '
127 mkdir .git/rr-cache &&
128 prime_resolve_undo &&
129 echo record the resolution &&
131 rerere_id=$(cd .git/rr-cache && echo */postimage) &&
132 rerere_id=${rerere_id%/postimage} &&
133 test -f .git/rr-cache/$rerere_id/postimage &&
134 git checkout -m fi/le &&
135 echo resurrect the conflict &&
136 grep "^=======" fi/le &&
137 echo reresolve the conflict &&
139 test "z$(cat fi/le)" = zdifferent &&
140 echo register the resolution again &&
142 check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
143 test -z "$(git ls-files -u)" &&
144 git rerere forget fi/le &&
145 ! test -f .git/rr-cache/$rerere_id/postimage &&
146 tr "\0" "\n" <.git/MERGE_RR >actual &&
147 echo "$rerere_id fi/le" >expect &&
148 test_cmp expect actual
151 test_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 &&
174 test_cmp expect actual
177 test_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
185 test_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