blob: da581ec19ac619cef717a4a3b4dc34f55c0142b8 [file] [log] [blame]
Jeff Kingcd437122009-03-20 02:00:43 -04001#!/bin/sh
2
3test_description='Test reflog display routines'
Johannes Schindelin06d53142020-11-18 23:44:21 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Ævar Arnfjörð Bjarmason81ffbf82022-04-13 22:01:52 +02007TEST_PASSES_SANITIZE_LEAK=true
Jeff Kingcd437122009-03-20 02:00:43 -04008. ./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
brian m. carlsond3438d12018-03-25 19:20:50 +000017commit=$(git rev-parse --short HEAD)
Jeff Kingcd437122009-03-20 02:00:43 -040018cat >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
brian m. carlsond3438d12018-03-25 19:20:50 +000028cat >expect <<EOF
29$commit HEAD@{0}: commit (initial): one
Jeff Kingcd437122009-03-20 02:00:43 -040030EOF
31test_expect_success 'oneline reflog format' '
32 git log -g -1 --oneline >actual &&
33 test_cmp expect actual
34'
35
Michael J Gruber21d26162011-04-01 11:20:32 +020036test_expect_success 'reflog default format' '
37 git reflog -1 >actual &&
38 test_cmp expect actual
39'
40
brian m. carlsond3438d12018-03-25 19:20:50 +000041cat >expect <<EOF
42commit $commit
Michael J Gruber21d26162011-04-01 11:20:32 +020043Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
44Reflog message: commit (initial): one
45Author: A U Thor <author@example.com>
46
47 one
48EOF
Michael J Gruber4b56cf52011-04-01 11:20:33 +020049test_expect_success 'override reflog default format' '
Michael J Gruber21d26162011-04-01 11:20:32 +020050 git reflog --format=short -1 >actual &&
51 test_cmp expect actual
52'
53
Jeff Kingcd437122009-03-20 02:00:43 -040054cat >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
brian m. carlsond3438d12018-03-25 19:20:50 +000064cat >expect <<EOF
65$commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
Jeff Kingcd437122009-03-20 02:00:43 -040066EOF
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
72cat >expect <<'EOF'
Jeff King7904af12012-05-04 01:23:14 -040073HEAD@{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
80cat >expect <<'EOF'
Junio C Hamano55ccf852012-05-07 14:11:32 -070081Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
Jeff Kingcd437122009-03-20 02:00:43 -040082Reflog message: commit (initial): one
83EOF
84test_expect_success 'using --date= shows reflog date (multiline)' '
Junio C Hamano55ccf852012-05-07 14:11:32 -070085 git log -g -1 --date=default >tmp &&
Jeff Kingcd437122009-03-20 02:00:43 -040086 grep ^Reflog <tmp >actual &&
87 test_cmp expect actual
88'
89
brian m. carlsond3438d12018-03-25 19:20:50 +000090cat >expect <<EOF
91$commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
Jeff Kingcd437122009-03-20 02:00:43 -040092EOF
93test_expect_success 'using --date= shows reflog date (oneline)' '
Junio C Hamano55ccf852012-05-07 14:11:32 -070094 git log -g -1 --oneline --date=default >actual &&
Jeff Kingcd437122009-03-20 02:00:43 -040095 test_cmp expect actual
96'
97
Jeff King7904af12012-05-04 01:23:14 -040098cat >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
brian m. carlsond3438d12018-03-25 19:20:50 +0000117cat >expect <<EOF
118$commit HEAD@{0}: commit (initial): one
Jeff King7904af12012-05-04 01:23:14 -0400119EOF
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
Jeff Kingf026c752012-05-04 01:25:18 -0400129test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
Jeff King7904af12012-05-04 01:23:14 -0400130 test_config log.date raw &&
131 git log -g -1 --format=%gd >actual &&
132 test_cmp expect actual
133'
134
Jeff King794151e2012-05-04 01:27:25 -0400135cat >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
Dave Olszewski8fcaca32010-03-13 14:47:05 -0800143test_expect_success 'empty reflog file' '
144 git branch empty &&
David Turnerd0ab0582015-07-27 18:57:08 -0400145 git reflog expire --expire=all refs/heads/empty &&
Dave Olszewski8fcaca32010-03-13 14:47:05 -0800146
147 git log -g empty >actual &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200148 test_must_be_empty actual
Dave Olszewski8fcaca32010-03-13 14:47:05 -0800149'
150
Thomas Rast838f9a12013-08-03 12:36:15 +0200151# 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 (
Eric Sunshinef2deabf2018-07-01 20:23:56 -0400165 cat log.one && echo &&
166 cat log.two && echo &&
167 cat log.one && echo &&
Thomas Rast838f9a12013-08-03 12:36:15 +0200168 cat log.two
169 ) >expect &&
170 test_cmp expect actual
171'
172
Jeff Kingcd437122009-03-20 02:00:43 -0400173test_done