Raw
1 #!/bin/sh
2
3 test_description='git reflog --updateref'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8 git init -b main repo &&
9 (
10 cd repo &&
11
12 test_commit A &&
13 test_commit B &&
14 test_commit C &&
15
16 git reflog HEAD >expect &&
17 git reset --hard HEAD~ &&
18 # Make sure that the reflog does not point to the same commit
19 # as HEAD.
20 git reflog delete HEAD@{0} &&
21 git reflog HEAD >actual &&
22 test_cmp expect actual
23 )
24 '
25
26 test_reflog_updateref () {
27 exp=$1
28 shift
29 args="$@"
30
31 test_expect_success "get '$exp' with '$args'" '
32 test_when_finished "rm -rf copy" &&
33 cp -R repo copy &&
34
35 (
36 cd copy &&
37
38 $args &&
39 git rev-parse $exp >expect &&
40 git rev-parse HEAD >actual &&
41
42 test_cmp expect actual
43 )
44 '
45 }
46
47 test_reflog_updateref B git reflog delete --updateref HEAD@{0}
48 test_reflog_updateref B git reflog delete --updateref HEAD@{1}
49 test_reflog_updateref C git reflog delete --updateref main@{0}
50 test_reflog_updateref B git reflog delete --updateref main@{1}
51 test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{0}
52 test_reflog_updateref B git reflog delete --updateref --rewrite HEAD@{1}
53 test_reflog_updateref C git reflog delete --updateref --rewrite main@{0}
54 test_reflog_updateref B git reflog delete --updateref --rewrite main@{1}
55 test_reflog_updateref B test_must_fail git reflog expire HEAD@{0}
56 test_reflog_updateref B test_must_fail git reflog expire HEAD@{1}
57 test_reflog_updateref B test_must_fail git reflog expire main@{0}
58 test_reflog_updateref B test_must_fail git reflog expire main@{1}
59 test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{0}
60 test_reflog_updateref B test_must_fail git reflog expire --updateref HEAD@{1}
61 test_reflog_updateref B test_must_fail git reflog expire --updateref main@{0}
62 test_reflog_updateref B test_must_fail git reflog expire --updateref main@{1}
63 test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{0}
64 test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite HEAD@{1}
65 test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{0}
66 test_reflog_updateref B test_must_fail git reflog expire --updateref --rewrite main@{1}
67
68 test_done