Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test reflog display routines' |
Johannes Schindelin | 06d5314 | 2020-11-18 23:44:21 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success 'setup' ' |
| 10 | echo content >file && |
| 11 | git add file && |
| 12 | test_tick && |
| 13 | git commit -m one |
| 14 | ' |
| 15 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 16 | commit=$(git rev-parse --short HEAD) |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 17 | cat >expect <<'EOF' |
| 18 | Reflog: HEAD@{0} (C O Mitter <committer@example.com>) |
| 19 | Reflog message: commit (initial): one |
| 20 | EOF |
| 21 | test_expect_success 'log -g shows reflog headers' ' |
| 22 | git log -g -1 >tmp && |
| 23 | grep ^Reflog <tmp >actual && |
| 24 | test_cmp expect actual |
| 25 | ' |
| 26 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 27 | cat >expect <<EOF |
| 28 | $commit HEAD@{0}: commit (initial): one |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 29 | EOF |
| 30 | test_expect_success 'oneline reflog format' ' |
| 31 | git log -g -1 --oneline >actual && |
| 32 | test_cmp expect actual |
| 33 | ' |
| 34 | |
Michael J Gruber | 21d2616 | 2011-04-01 11:20:32 +0200 | [diff] [blame] | 35 | test_expect_success 'reflog default format' ' |
| 36 | git reflog -1 >actual && |
| 37 | test_cmp expect actual |
| 38 | ' |
| 39 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 40 | cat >expect <<EOF |
| 41 | commit $commit |
Michael J Gruber | 21d2616 | 2011-04-01 11:20:32 +0200 | [diff] [blame] | 42 | Reflog: HEAD@{0} (C O Mitter <committer@example.com>) |
| 43 | Reflog message: commit (initial): one |
| 44 | Author: A U Thor <author@example.com> |
| 45 | |
| 46 | one |
| 47 | EOF |
Michael J Gruber | 4b56cf5 | 2011-04-01 11:20:33 +0200 | [diff] [blame] | 48 | test_expect_success 'override reflog default format' ' |
Michael J Gruber | 21d2616 | 2011-04-01 11:20:32 +0200 | [diff] [blame] | 49 | git reflog --format=short -1 >actual && |
| 50 | test_cmp expect actual |
| 51 | ' |
| 52 | |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 53 | cat >expect <<'EOF' |
| 54 | Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>) |
| 55 | Reflog message: commit (initial): one |
| 56 | EOF |
| 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 |
| 61 | ' |
| 62 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 63 | cat >expect <<EOF |
| 64 | $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 65 | EOF |
| 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 |
| 69 | ' |
| 70 | |
| 71 | cat >expect <<'EOF' |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 72 | HEAD@{Thu Apr 7 15:13:13 2005 -0700} |
| 73 | EOF |
| 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 |
| 77 | ' |
| 78 | |
| 79 | cat >expect <<'EOF' |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 80 | Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>) |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 81 | Reflog message: commit (initial): one |
| 82 | EOF |
| 83 | test_expect_success 'using --date= shows reflog date (multiline)' ' |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 84 | git log -g -1 --date=default >tmp && |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 85 | grep ^Reflog <tmp >actual && |
| 86 | test_cmp expect actual |
| 87 | ' |
| 88 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 89 | cat >expect <<EOF |
| 90 | $commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 91 | EOF |
| 92 | test_expect_success 'using --date= shows reflog date (oneline)' ' |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 93 | git log -g -1 --oneline --date=default >actual && |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 94 | test_cmp expect actual |
| 95 | ' |
| 96 | |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 97 | cat >expect <<'EOF' |
| 98 | HEAD@{1112911993 -0700} |
| 99 | EOF |
| 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 |
| 103 | ' |
| 104 | |
| 105 | cat >expect <<'EOF' |
| 106 | Reflog: HEAD@{0} (C O Mitter <committer@example.com>) |
| 107 | Reflog message: commit (initial): one |
| 108 | EOF |
| 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 |
| 114 | ' |
| 115 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 116 | cat >expect <<EOF |
| 117 | $commit HEAD@{0}: commit (initial): one |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 118 | EOF |
| 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 |
| 123 | ' |
| 124 | |
| 125 | cat >expect <<'EOF' |
| 126 | HEAD@{0} |
| 127 | EOF |
Jeff King | f026c75 | 2012-05-04 01:25:18 -0400 | [diff] [blame] | 128 | test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' ' |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 129 | test_config log.date raw && |
| 130 | git log -g -1 --format=%gd >actual && |
| 131 | test_cmp expect actual |
| 132 | ' |
| 133 | |
Jeff King | 794151e | 2012-05-04 01:27:25 -0400 | [diff] [blame] | 134 | cat >expect <<'EOF' |
| 135 | HEAD@{0} |
| 136 | EOF |
| 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 |
| 140 | ' |
| 141 | |
Dave Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 142 | test_expect_success 'empty reflog file' ' |
| 143 | git branch empty && |
David Turner | d0ab058 | 2015-07-27 18:57:08 -0400 | [diff] [blame] | 144 | git reflog expire --expire=all refs/heads/empty && |
Dave Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 145 | |
| 146 | git log -g empty >actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 147 | test_must_be_empty actual |
Dave Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 148 | ' |
| 149 | |
Thomas Rast | 838f9a1 | 2013-08-03 12:36:15 +0200 | [diff] [blame] | 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' ' |
| 154 | test_commit two && |
| 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 && |
| 163 | ( |
Eric Sunshine | f2deabf | 2018-07-01 20:23:56 -0400 | [diff] [blame] | 164 | cat log.one && echo && |
| 165 | cat log.two && echo && |
| 166 | cat log.one && echo && |
Thomas Rast | 838f9a1 | 2013-08-03 12:36:15 +0200 | [diff] [blame] | 167 | cat log.two |
| 168 | ) >expect && |
| 169 | test_cmp expect actual |
| 170 | ' |
| 171 | |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 172 | test_done |