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 | |
Ævar Arnfjörð Bjarmason | 81ffbf8 | 2022-04-13 22:01:52 +0200 | [diff] [blame] | 7 | TEST_PASSES_SANITIZE_LEAK=true |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup' ' |
| 11 | echo content >file && |
| 12 | git add file && |
| 13 | test_tick && |
| 14 | git commit -m one |
| 15 | ' |
| 16 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 17 | commit=$(git rev-parse --short HEAD) |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 18 | cat >expect <<'EOF' |
| 19 | Reflog: HEAD@{0} (C O Mitter <committer@example.com>) |
| 20 | Reflog message: commit (initial): one |
| 21 | EOF |
| 22 | test_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. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 28 | cat >expect <<EOF |
| 29 | $commit HEAD@{0}: commit (initial): one |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 30 | EOF |
| 31 | test_expect_success 'oneline reflog format' ' |
| 32 | git log -g -1 --oneline >actual && |
| 33 | test_cmp expect actual |
| 34 | ' |
| 35 | |
Michael J Gruber | 21d2616 | 2011-04-01 11:20:32 +0200 | [diff] [blame] | 36 | test_expect_success 'reflog default format' ' |
| 37 | git reflog -1 >actual && |
| 38 | test_cmp expect actual |
| 39 | ' |
| 40 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 41 | cat >expect <<EOF |
| 42 | commit $commit |
Michael J Gruber | 21d2616 | 2011-04-01 11:20:32 +0200 | [diff] [blame] | 43 | Reflog: HEAD@{0} (C O Mitter <committer@example.com>) |
| 44 | Reflog message: commit (initial): one |
| 45 | Author: A U Thor <author@example.com> |
| 46 | |
| 47 | one |
| 48 | EOF |
Michael J Gruber | 4b56cf5 | 2011-04-01 11:20:33 +0200 | [diff] [blame] | 49 | test_expect_success 'override reflog default format' ' |
Michael J Gruber | 21d2616 | 2011-04-01 11:20:32 +0200 | [diff] [blame] | 50 | git reflog --format=short -1 >actual && |
| 51 | test_cmp expect actual |
| 52 | ' |
| 53 | |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 54 | cat >expect <<'EOF' |
| 55 | Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>) |
| 56 | Reflog message: commit (initial): one |
| 57 | EOF |
| 58 | test_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. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 64 | cat >expect <<EOF |
| 65 | $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] | 66 | EOF |
| 67 | test_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 | |
| 72 | cat >expect <<'EOF' |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 73 | HEAD@{Thu Apr 7 15:13:13 2005 -0700} |
| 74 | EOF |
| 75 | test_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 | |
| 80 | cat >expect <<'EOF' |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 81 | 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] | 82 | Reflog message: commit (initial): one |
| 83 | EOF |
| 84 | test_expect_success 'using --date= shows reflog date (multiline)' ' |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 85 | git log -g -1 --date=default >tmp && |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 86 | grep ^Reflog <tmp >actual && |
| 87 | test_cmp expect actual |
| 88 | ' |
| 89 | |
brian m. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 90 | cat >expect <<EOF |
| 91 | $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] | 92 | EOF |
| 93 | test_expect_success 'using --date= shows reflog date (oneline)' ' |
Junio C Hamano | 55ccf85 | 2012-05-07 14:11:32 -0700 | [diff] [blame] | 94 | git log -g -1 --oneline --date=default >actual && |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 95 | test_cmp expect actual |
| 96 | ' |
| 97 | |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 98 | cat >expect <<'EOF' |
| 99 | HEAD@{1112911993 -0700} |
| 100 | EOF |
| 101 | test_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 | |
| 106 | cat >expect <<'EOF' |
| 107 | Reflog: HEAD@{0} (C O Mitter <committer@example.com>) |
| 108 | Reflog message: commit (initial): one |
| 109 | EOF |
| 110 | test_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. carlson | d3438d1 | 2018-03-25 19:20:50 +0000 | [diff] [blame] | 117 | cat >expect <<EOF |
| 118 | $commit HEAD@{0}: commit (initial): one |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 119 | EOF |
| 120 | test_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 | |
| 126 | cat >expect <<'EOF' |
| 127 | HEAD@{0} |
| 128 | EOF |
Jeff King | f026c75 | 2012-05-04 01:25:18 -0400 | [diff] [blame] | 129 | test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' ' |
Jeff King | 7904af1 | 2012-05-04 01:23:14 -0400 | [diff] [blame] | 130 | test_config log.date raw && |
| 131 | git log -g -1 --format=%gd >actual && |
| 132 | test_cmp expect actual |
| 133 | ' |
| 134 | |
Jeff King | 794151e | 2012-05-04 01:27:25 -0400 | [diff] [blame] | 135 | cat >expect <<'EOF' |
| 136 | HEAD@{0} |
| 137 | EOF |
| 138 | test_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 Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 143 | test_expect_success 'empty reflog file' ' |
| 144 | git branch empty && |
David Turner | d0ab058 | 2015-07-27 18:57:08 -0400 | [diff] [blame] | 145 | git reflog expire --expire=all refs/heads/empty && |
Dave Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 146 | |
| 147 | git log -g empty >actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 148 | test_must_be_empty actual |
Dave Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 149 | ' |
| 150 | |
Thomas Rast | 838f9a1 | 2013-08-03 12:36:15 +0200 | [diff] [blame] | 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. |
| 154 | test_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 Sunshine | f2deabf | 2018-07-01 20:23:56 -0400 | [diff] [blame] | 165 | cat log.one && echo && |
| 166 | cat log.two && echo && |
| 167 | cat log.one && echo && |
Thomas Rast | 838f9a1 | 2013-08-03 12:36:15 +0200 | [diff] [blame] | 168 | cat log.two |
| 169 | ) >expect && |
| 170 | test_cmp expect actual |
| 171 | ' |
| 172 | |
Jeff King | cd43712 | 2009-03-20 02:00:43 -0400 | [diff] [blame] | 173 | test_done |