Imported Upstream version 2.18.0
[platform/upstream/git.git] / t / t1411-reflog-show.sh
1 #!/bin/sh
2
3 test_description='Test reflog display routines'
4 . ./test-lib.sh
5
6 test_expect_success 'setup' '
7         echo content >file &&
8         git add file &&
9         test_tick &&
10         git commit -m one
11 '
12
13 commit=$(git rev-parse --short HEAD)
14 cat >expect <<'EOF'
15 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
16 Reflog message: commit (initial): one
17 EOF
18 test_expect_success 'log -g shows reflog headers' '
19         git log -g -1 >tmp &&
20         grep ^Reflog <tmp >actual &&
21         test_cmp expect actual
22 '
23
24 cat >expect <<EOF
25 $commit HEAD@{0}: commit (initial): one
26 EOF
27 test_expect_success 'oneline reflog format' '
28         git log -g -1 --oneline >actual &&
29         test_cmp expect actual
30 '
31
32 test_expect_success 'reflog default format' '
33         git reflog -1 >actual &&
34         test_cmp expect actual
35 '
36
37 cat >expect <<EOF
38 commit $commit
39 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
40 Reflog message: commit (initial): one
41 Author: A U Thor <author@example.com>
42
43     one
44 EOF
45 test_expect_success 'override reflog default format' '
46         git reflog --format=short -1 >actual &&
47         test_cmp expect actual
48 '
49
50 cat >expect <<'EOF'
51 Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
52 Reflog message: commit (initial): one
53 EOF
54 test_expect_success 'using @{now} syntax shows reflog date (multiline)' '
55         git log -g -1 HEAD@{now} >tmp &&
56         grep ^Reflog <tmp >actual &&
57         test_cmp expect actual
58 '
59
60 cat >expect <<EOF
61 $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
62 EOF
63 test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
64         git log -g -1 --oneline HEAD@{now} >actual &&
65         test_cmp expect actual
66 '
67
68 cat >expect <<'EOF'
69 HEAD@{Thu Apr 7 15:13:13 2005 -0700}
70 EOF
71 test_expect_success 'using @{now} syntax shows reflog date (format=%gd)' '
72         git log -g -1 --format=%gd HEAD@{now} >actual &&
73         test_cmp expect actual
74 '
75
76 cat >expect <<'EOF'
77 Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
78 Reflog message: commit (initial): one
79 EOF
80 test_expect_success 'using --date= shows reflog date (multiline)' '
81         git log -g -1 --date=default >tmp &&
82         grep ^Reflog <tmp >actual &&
83         test_cmp expect actual
84 '
85
86 cat >expect <<EOF
87 $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
88 EOF
89 test_expect_success 'using --date= shows reflog date (oneline)' '
90         git log -g -1 --oneline --date=default >actual &&
91         test_cmp expect actual
92 '
93
94 cat >expect <<'EOF'
95 HEAD@{1112911993 -0700}
96 EOF
97 test_expect_success 'using --date= shows reflog date (format=%gd)' '
98         git log -g -1 --format=%gd --date=raw >actual &&
99         test_cmp expect actual
100 '
101
102 cat >expect <<'EOF'
103 Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
104 Reflog message: commit (initial): one
105 EOF
106 test_expect_success 'log.date does not invoke "--date" magic (multiline)' '
107         test_config log.date raw &&
108         git log -g -1 >tmp &&
109         grep ^Reflog <tmp >actual &&
110         test_cmp expect actual
111 '
112
113 cat >expect <<EOF
114 $commit HEAD@{0}: commit (initial): one
115 EOF
116 test_expect_success 'log.date does not invoke "--date" magic (oneline)' '
117         test_config log.date raw &&
118         git log -g -1 --oneline >actual &&
119         test_cmp expect actual
120 '
121
122 cat >expect <<'EOF'
123 HEAD@{0}
124 EOF
125 test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
126         test_config log.date raw &&
127         git log -g -1 --format=%gd >actual &&
128         test_cmp expect actual
129 '
130
131 cat >expect <<'EOF'
132 HEAD@{0}
133 EOF
134 test_expect_success '--date magic does not override explicit @{0} syntax' '
135         git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
136         test_cmp expect actual
137 '
138
139 : >expect
140 test_expect_success 'empty reflog file' '
141         git branch empty &&
142         git reflog expire --expire=all refs/heads/empty &&
143
144         git log -g empty >actual &&
145         test_cmp expect actual
146 '
147
148 # This guards against the alternative of showing the diffs vs. the
149 # reflog ancestor.  The reflog used is designed to list the commits
150 # more than once, so as to exercise the corresponding logic.
151 test_expect_success 'git log -g -p shows diffs vs. parents' '
152         test_commit two &&
153         git branch flipflop &&
154         git update-ref refs/heads/flipflop -m flip1 HEAD^ &&
155         git update-ref refs/heads/flipflop -m flop1 HEAD &&
156         git update-ref refs/heads/flipflop -m flip2 HEAD^ &&
157         git log -g -p flipflop >reflog &&
158         grep -v ^Reflog reflog >actual &&
159         git log -1 -p HEAD^ >log.one &&
160         git log -1 -p HEAD >log.two &&
161         (
162                 cat log.one; echo
163                 cat log.two; echo
164                 cat log.one; echo
165                 cat log.two
166         ) >expect &&
167         test_cmp expect actual
168 '
169
170 test_expect_success 'reflog exists works' '
171         git reflog exists refs/heads/master &&
172         ! git reflog exists refs/heads/nonexistent
173 '
174
175 test_done