3 test_description='Test reflog display routines'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success 'setup' '
16 commit=$(git rev-parse --short HEAD)
18 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
19 Reflog message: commit (initial): one
21 test_expect_success 'log -g shows reflog headers' '
23 grep ^Reflog <tmp >actual &&
24 test_cmp expect actual
28 $commit HEAD@{0}: commit (initial): one
30 test_expect_success 'oneline reflog format' '
31 git log -g -1 --oneline >actual &&
32 test_cmp expect actual
35 test_expect_success 'reflog default format' '
36 git reflog -1 >actual &&
37 test_cmp expect actual
42 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
43 Reflog message: commit (initial): one
44 Author: A U Thor <author@example.com>
48 test_expect_success 'override reflog default format' '
49 git reflog --format=short -1 >actual &&
50 test_cmp expect actual
54 Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
55 Reflog message: commit (initial): one
57 test_expect_success 'using @{now} syntax shows reflog date (multiline)' '
58 git log -g -1 HEAD@{now} >tmp &&
59 grep ^Reflog <tmp >actual &&
60 test_cmp expect actual
64 $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
66 test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
67 git log -g -1 --oneline HEAD@{now} >actual &&
68 test_cmp expect actual
72 HEAD@{Thu Apr 7 15:13:13 2005 -0700}
74 test_expect_success 'using @{now} syntax shows reflog date (format=%gd)' '
75 git log -g -1 --format=%gd HEAD@{now} >actual &&
76 test_cmp expect actual
80 Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
81 Reflog message: commit (initial): one
83 test_expect_success 'using --date= shows reflog date (multiline)' '
84 git log -g -1 --date=default >tmp &&
85 grep ^Reflog <tmp >actual &&
86 test_cmp expect actual
90 $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
92 test_expect_success 'using --date= shows reflog date (oneline)' '
93 git log -g -1 --oneline --date=default >actual &&
94 test_cmp expect actual
98 HEAD@{1112911993 -0700}
100 test_expect_success 'using --date= shows reflog date (format=%gd)' '
101 git log -g -1 --format=%gd --date=raw >actual &&
102 test_cmp expect actual
106 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
107 Reflog message: commit (initial): one
109 test_expect_success 'log.date does not invoke "--date" magic (multiline)' '
110 test_config log.date raw &&
111 git log -g -1 >tmp &&
112 grep ^Reflog <tmp >actual &&
113 test_cmp expect actual
117 $commit HEAD@{0}: commit (initial): one
119 test_expect_success 'log.date does not invoke "--date" magic (oneline)' '
120 test_config log.date raw &&
121 git log -g -1 --oneline >actual &&
122 test_cmp expect actual
128 test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
129 test_config log.date raw &&
130 git log -g -1 --format=%gd >actual &&
131 test_cmp expect actual
137 test_expect_success '--date magic does not override explicit @{0} syntax' '
138 git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
139 test_cmp expect actual
142 test_expect_success 'empty reflog file' '
144 git reflog expire --expire=all refs/heads/empty &&
146 git log -g empty >actual &&
147 test_must_be_empty actual
150 # This guards against the alternative of showing the diffs vs. the
151 # reflog ancestor. The reflog used is designed to list the commits
152 # more than once, so as to exercise the corresponding logic.
153 test_expect_success 'git log -g -p shows diffs vs. parents' '
155 git branch flipflop &&
156 git update-ref refs/heads/flipflop -m flip1 HEAD^ &&
157 git update-ref refs/heads/flipflop -m flop1 HEAD &&
158 git update-ref refs/heads/flipflop -m flip2 HEAD^ &&
159 git log -g -p flipflop >reflog &&
160 grep -v ^Reflog reflog >actual &&
161 git log -1 -p HEAD^ >log.one &&
162 git log -1 -p HEAD >log.two &&
164 cat log.one && echo &&
165 cat log.two && echo &&
166 cat log.one && echo &&
169 test_cmp expect actual
172 test_expect_success 'reflog exists works' '
173 git reflog exists refs/heads/main &&
174 ! git reflog exists refs/heads/nonexistent