3 test_description
='Test reflog display routines'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'setup' '
17 commit
=$
(git rev-parse
--short HEAD
)
19 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
20 Reflog message: commit (initial): one
22 test_expect_success
'log -g shows reflog headers' '
24 grep ^Reflog <tmp >actual &&
25 test_cmp expect actual
29 $commit HEAD@{0}: commit (initial): one
31 test_expect_success
'oneline reflog format' '
32 git log -g -1 --oneline >actual &&
33 test_cmp expect actual
36 test_expect_success
'reflog default format' '
37 git reflog -1 >actual &&
38 test_cmp expect actual
43 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
44 Reflog message: commit (initial): one
45 Author: A U Thor <author@example.com>
49 test_expect_success
'override reflog default format' '
50 git reflog --format=short -1 >actual &&
51 test_cmp expect actual
55 Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
56 Reflog message: commit (initial): one
58 test_expect_success
'using @{now} syntax shows reflog date (multiline)' '
59 git log -g -1 HEAD@{now} >tmp &&
60 grep ^Reflog <tmp >actual &&
61 test_cmp expect actual
65 $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
67 test_expect_success
'using @{now} syntax shows reflog date (oneline)' '
68 git log -g -1 --oneline HEAD@{now} >actual &&
69 test_cmp expect actual
73 HEAD@{Thu Apr 7 15:13:13 2005 -0700}
75 test_expect_success
'using @{now} syntax shows reflog date (format=%gd)' '
76 git log -g -1 --format=%gd HEAD@{now} >actual &&
77 test_cmp expect actual
81 Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
82 Reflog message: commit (initial): one
84 test_expect_success
'using --date= shows reflog date (multiline)' '
85 git log -g -1 --date=default >tmp &&
86 grep ^Reflog <tmp >actual &&
87 test_cmp expect actual
91 $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
93 test_expect_success
'using --date= shows reflog date (oneline)' '
94 git log -g -1 --oneline --date=default >actual &&
95 test_cmp expect actual
99 HEAD@{1112911993 -0700}
101 test_expect_success
'using --date= shows reflog date (format=%gd)' '
102 git log -g -1 --format=%gd --date=raw >actual &&
103 test_cmp expect actual
107 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
108 Reflog message: commit (initial): one
110 test_expect_success
'log.date does not invoke "--date" magic (multiline)' '
111 test_config log.date raw &&
112 git log -g -1 >tmp &&
113 grep ^Reflog <tmp >actual &&
114 test_cmp expect actual
118 $commit HEAD@{0}: commit (initial): one
120 test_expect_success
'log.date does not invoke "--date" magic (oneline)' '
121 test_config log.date raw &&
122 git log -g -1 --oneline >actual &&
123 test_cmp expect actual
129 test_expect_success
'log.date does not invoke "--date" magic (format=%gd)' '
130 test_config log.date raw &&
131 git log -g -1 --format=%gd >actual &&
132 test_cmp expect actual
138 test_expect_success
'--date magic does not override explicit @{0} syntax' '
139 git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
140 test_cmp expect actual
143 test_expect_success
'empty reflog file' '
145 git reflog expire --expire=all refs/heads/empty &&
147 git log -g empty >actual &&
148 test_must_be_empty actual
151 # This guards against the alternative of showing the diffs vs. the
152 # reflog ancestor. The reflog used is designed to list the commits
153 # more than once, so as to exercise the corresponding logic.
154 test_expect_success
'git log -g -p shows diffs vs. parents' '
156 git branch flipflop &&
157 git update-ref refs/heads/flipflop -m flip1 HEAD^ &&
158 git update-ref refs/heads/flipflop -m flop1 HEAD &&
159 git update-ref refs/heads/flipflop -m flip2 HEAD^ &&
160 git log -g -p flipflop >reflog &&
161 grep -v ^Reflog reflog >actual &&
162 git log -1 -p HEAD^ >log.one &&
163 git log -1 -p HEAD >log.two &&
165 cat log.one && echo &&
166 cat log.two && echo &&
167 cat log.one && echo &&
170 test_cmp expect actual