Skip to content

Commit 5ac15ad

Browse files
avargitster
authored andcommitted
reflog tests: add --updateref tests
Add tests that cover blindspots in "git reflog delete --updateref" behavior. Before this change removing the "type & REF_ISSYMREF" check added in 5e6f003 (reflog_expire(): ignore --updateref for symbolic references, 2015-03-03) would not fail any tests. The "--updateref" option was added in 55f1056 (git-reflog: add option --updateref to write the last reflog sha1 into the ref, 2008-02-22) for use in git-stash.sh, see e25d5f9 (git-stash: add new 'drop' subcommand, 2008-02-22). Even though the regression test I need is just the "C" case here, let's test all these combinations for good measure. I started out doing these as a for-loop, but I think this is more readable. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c339ff6 commit 5ac15ad

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

t/t1417-reflog-updateref.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
3+
test_description='git reflog --updateref'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
6+
. ./test-lib.sh
7+
8+
test_expect_success 'setup' '
9+
git init -b main repo &&
10+
(
11+
cd repo &&
12+
13+
test_commit A &&
14+
test_commit B &&
15+
test_commit C &&
16+
17+
cp .git/logs/HEAD HEAD.old &&
18+
git reset --hard HEAD~ &&
19+
cp HEAD.old .git/logs/HEAD
20+
)
21+
'
22+
23+
test_reflog_updateref () {
24+
exp=$1
25+
shift
26+
args="$@"
27+
28+
test_expect_success REFFILES "get '$exp' with '$args'" '
29+
test_when_finished "rm -rf copy" &&
30+
cp -R repo copy &&
31+
32+
(
33+
cd copy &&
34+
35+
$args &&
36+
git rev-parse $exp >expect &&
37+
git rev-parse HEAD >actual &&
38+
39+
test_cmp expect actual
40+
)
41+
'
42+
}
43+
44+
test_reflog_updateref B git reflog delete --updateref HEAD@{0}
45+
test_reflog_updateref B git reflog delete --updateref HEAD@{1}
46+
test_reflog_updateref C git reflog delete --updateref main@{0}
47+
test_reflog_updateref B git reflog delete --updateref main@{1}
48+
test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{0}
49+
test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{1}
50+
test_reflog_updateref C git reflog delete --updateref --rewrite main@{0}
51+
test_reflog_updateref B git reflog delete --updateref --rewrite main@{1}
52+
test_reflog_updateref B test_must_fail git reflog expire HEAD@{0}
53+
test_reflog_updateref B test_must_fail git reflog expire HEAD@{1}
54+
test_reflog_updateref B test_must_fail git reflog expire main@{0}
55+
test_reflog_updateref B test_must_fail git reflog expire main@{1}
56+
test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{0}
57+
test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{1}
58+
test_reflog_updateref B test_must_fail git reflog expire --updateref main@{0}
59+
test_reflog_updateref B test_must_fail git reflog expire --updateref main@{1}
60+
test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{0}
61+
test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{1}
62+
test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{0}
63+
test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{1}
64+
65+
test_done

0 commit comments

Comments
 (0)