]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1411-reflog-show.sh
The third batch
[thirdparty/git.git] / t / t1411-reflog-show.sh
CommitLineData
cd437120
JK
1#!/bin/sh
2
3test_description='Test reflog display routines'
06d53148 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
81ffbf83 7TEST_PASSES_SANITIZE_LEAK=true
cd437120
JK
8. ./test-lib.sh
9
10test_expect_success 'setup' '
11 echo content >file &&
12 git add file &&
13 test_tick &&
14 git commit -m one
15'
16
d3438d1a 17commit=$(git rev-parse --short HEAD)
cd437120
JK
18cat >expect <<'EOF'
19Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
20Reflog message: commit (initial): one
21EOF
22test_expect_success 'log -g shows reflog headers' '
23 git log -g -1 >tmp &&
24 grep ^Reflog <tmp >actual &&
25 test_cmp expect actual
26'
27
d3438d1a 28cat >expect <<EOF
29$commit HEAD@{0}: commit (initial): one
cd437120
JK
30EOF
31test_expect_success 'oneline reflog format' '
32 git log -g -1 --oneline >actual &&
33 test_cmp expect actual
34'
35
21d2616a
MG
36test_expect_success 'reflog default format' '
37 git reflog -1 >actual &&
38 test_cmp expect actual
39'
40
d3438d1a 41cat >expect <<EOF
42commit $commit
21d2616a
MG
43Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
44Reflog message: commit (initial): one
45Author: A U Thor <author@example.com>
46
47 one
48EOF
4b56cf58 49test_expect_success 'override reflog default format' '
21d2616a
MG
50 git reflog --format=short -1 >actual &&
51 test_cmp expect actual
52'
53
cd437120
JK
54cat >expect <<'EOF'
55Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
56Reflog message: commit (initial): one
57EOF
58test_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
62'
63
d3438d1a 64cat >expect <<EOF
65$commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
cd437120
JK
66EOF
67test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
68 git log -g -1 --oneline HEAD@{now} >actual &&
69 test_cmp expect actual
70'
71
7904af1c
JK
72cat >expect <<'EOF'
73HEAD@{Thu Apr 7 15:13:13 2005 -0700}
74EOF
75test_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
78'
79
cd437120 80cat >expect <<'EOF'
55ccf85a 81Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
cd437120
JK
82Reflog message: commit (initial): one
83EOF
84test_expect_success 'using --date= shows reflog date (multiline)' '
55ccf85a 85 git log -g -1 --date=default >tmp &&
cd437120
JK
86 grep ^Reflog <tmp >actual &&
87 test_cmp expect actual
88'
89
d3438d1a 90cat >expect <<EOF
91$commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
cd437120
JK
92EOF
93test_expect_success 'using --date= shows reflog date (oneline)' '
55ccf85a 94 git log -g -1 --oneline --date=default >actual &&
cd437120
JK
95 test_cmp expect actual
96'
97
7904af1c
JK
98cat >expect <<'EOF'
99HEAD@{1112911993 -0700}
100EOF
101test_expect_success 'using --date= shows reflog date (format=%gd)' '
102 git log -g -1 --format=%gd --date=raw >actual &&
103 test_cmp expect actual
104'
105
106cat >expect <<'EOF'
107Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
108Reflog message: commit (initial): one
109EOF
110test_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
115'
116
d3438d1a 117cat >expect <<EOF
118$commit HEAD@{0}: commit (initial): one
7904af1c
JK
119EOF
120test_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
124'
125
126cat >expect <<'EOF'
127HEAD@{0}
128EOF
f026c756 129test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
7904af1c
JK
130 test_config log.date raw &&
131 git log -g -1 --format=%gd >actual &&
132 test_cmp expect actual
133'
134
794151e9
JK
135cat >expect <<'EOF'
136HEAD@{0}
137EOF
138test_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
141'
142
8fcaca3f
DO
143test_expect_success 'empty reflog file' '
144 git branch empty &&
d0ab0584 145 git reflog expire --expire=all refs/heads/empty &&
8fcaca3f
DO
146
147 git log -g empty >actual &&
1c5e94f4 148 test_must_be_empty actual
8fcaca3f
DO
149'
150
838f9a15
TR
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.
154test_expect_success 'git log -g -p shows diffs vs. parents' '
155 test_commit two &&
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 &&
164 (
f2deabfc
ES
165 cat log.one && echo &&
166 cat log.two && echo &&
167 cat log.one && echo &&
838f9a15
TR
168 cat log.two
169 ) >expect &&
170 test_cmp expect actual
171'
172
cd437120 173test_done