show-branch: show reflog message

Before, --reflog option would look for '\t' in the reflog message. As refs.c already parses the reflog line, the '\t' was never found, and show-branch --reflog would always say "(none)" as reflog message Add test. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed Dec 2, 2021 at 17:36 UTC f2463490c4ee3beded70bf69e49fb23552796ddc
2 files changed +22 -5
builtin/show-branch.c
+7 -5
@@ -761,6 +761,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
761 char *logmsg;
762 char *nth_desc;
763 const char *msg;
764 + char *end;
765 timestamp_t timestamp;
766 int tz;
767
@@ -770,11 +771,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
771 reflog = i;
772 break;
773 }
773 - msg = strchr(logmsg, '\t');
774 - if (!msg)
775 - msg = "(none)";
776 - else
777 - msg++;
774 +
775 + end = strchr(logmsg, '\n');
776 + if (end)
777 + *end = '\0';
778 +
779 + msg = (*logmsg == '\0') ? "(none)" : logmsg;
780 reflog_msg[i] = xstrfmt("(%s) %s",
781 show_date(timestamp, tz,
782 DATE_MODE(RELATIVE)),
t/t3202-show-branch.sh
+15
@@ -4,6 +4,9 @@ test_description='test show-branch'
4
5 . ./test-lib.sh
6
7 +# arbitrary reference time: 2009-08-30 19:20:00
8 +GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW
9 +
10 test_expect_success 'setup' '
11 test_commit initial &&
12 for i in $(test_seq 1 10)
@@ -146,4 +149,16 @@ test_expect_success 'show branch --merge-base with N arguments' '
149 test_cmp expect actual
150 '
151
152 +test_expect_success 'show branch --reflog=2' '
153 + sed "s/^> //" >expect <<-\EOF &&
154 + > ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10
155 + > ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10
156 + > --
157 + > + [refs/heads/branch10@{0}] branch10
158 + > ++ [refs/heads/branch10@{1}] initial
159 + EOF
160 + git show-branch --reflog=2 >actual &&
161 + test_cmp actual expect
162 +'
163 +
164 test_done