Skip to content

Commit 76bccbc

Browse files
john-caigitster
authored andcommitted
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 <[email protected]> Signed-off-by: John Cai <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 715d08a commit 76bccbc

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

t/t3903-stash.sh

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ diff_cmp () {
4141
rm -f "$1.compare" "$2.compare"
4242
}
4343

44-
test_expect_success 'stash some dirty working directory' '
44+
setup_stash() {
4545
echo 1 >file &&
4646
git add file &&
4747
echo unrelated >other-file &&
@@ -55,6 +55,10 @@ test_expect_success 'stash some dirty working directory' '
5555
git stash &&
5656
git diff-files --quiet &&
5757
git diff-index --cached --quiet HEAD
58+
}
59+
60+
test_expect_success 'stash some dirty working directory' '
61+
setup_stash
5862
'
5963

6064
cat >expect <<EOF
@@ -185,6 +189,43 @@ test_expect_success 'drop middle stash by index' '
185189
test 1 = $(git show HEAD:file)
186190
'
187191

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+
188229
test_expect_success 'stash pop' '
189230
git reset --hard &&
190231
git stash pop &&

0 commit comments

Comments
 (0)