stash: add tests to ensure reflog --rewrite --updatref behavior

There is missing test coverage to ensure that the resulting reflogs after a git stash drop has had its old oid rewritten if applicable, and if the refs/stash has been updated if applicable. Add two tests that verify both of these happen. Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Cai committed Mar 2, 2022 at 22:27 UTC 76bccbcfe2ff0d75302b0bf98b82aba95f8fc937
1 file changed +42 -1
t/t3903-stash.sh
+42 -1
@@ -41,7 +41,7 @@ diff_cmp () {
41 rm -f "$1.compare" "$2.compare"
42 }
43
44 -test_expect_success 'stash some dirty working directory' '
44 +setup_stash() {
45 echo 1 >file &&
46 git add file &&
47 echo unrelated >other-file &&
@@ -55,6 +55,10 @@ test_expect_success 'stash some dirty working directory' '
55 git stash &&
56 git diff-files --quiet &&
57 git diff-index --cached --quiet HEAD
58 +}
59 +
60 +test_expect_success 'stash some dirty working directory' '
61 + setup_stash
62 '
63
64 cat >expect <<EOF
@@ -185,6 +189,43 @@ test_expect_success 'drop middle stash by index' '
189 test 1 = $(git show HEAD:file)
190 '
191
192 +test_expect_success 'drop stash reflog updates refs/stash' '
193 + git reset --hard &&
194 + git rev-parse refs/stash >expect &&
195 + echo 9 >file &&
196 + git stash &&
197 + git stash drop stash@{0} &&
198 + git rev-parse refs/stash >actual &&
199 + test_cmp expect actual
200 +'
201 +
202 +test_expect_success REFFILES 'drop stash reflog updates refs/stash with rewrite' '
203 + git init repo &&
204 + (
205 + cd repo &&
206 + setup_stash
207 + ) &&
208 + echo 9 >repo/file &&
209 +
210 + old_oid="$(git -C repo rev-parse stash@{0})" &&
211 + git -C repo stash &&
212 + new_oid="$(git -C repo rev-parse stash@{0})" &&
213 +
214 + cat >expect <<-EOF &&
215 + $(test_oid zero) $old_oid
216 + $old_oid $new_oid
217 + EOF
218 + cut -d" " -f1-2 repo/.git/logs/refs/stash >actual &&
219 + test_cmp expect actual &&
220 +
221 + git -C repo stash drop stash@{1} &&
222 + cut -d" " -f1-2 repo/.git/logs/refs/stash >actual &&
223 + cat >expect <<-EOF &&
224 + $(test_oid zero) $new_oid
225 + EOF
226 + test_cmp expect actual
227 +'
228 +
229 test_expect_success 'stash pop' '
230 git reset --hard &&
231 git stash pop &&