show-branch: -g and --current are incompatible
commit41c64ae0e762d2c4ef1ddd578b8992967547dc5f
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Apr 2022 21:25:47 +0000 (21 14:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Apr 2022 21:26:42 +0000 (21 14:26 -0700)
treedce90c872513e4da793558d2081bc6bf9012f14f
parentd516b2db0af2221bd6b13e7347abdcb5830b2829
show-branch: -g and --current are incompatible

When "--current" is given to "git show-branch" running in the
"--reflog" mode, the code tries to reference a "reflog" message
that does not even exist.  This is because the --current is not
prepared to work in that mode.

The reason "--current" exists is to support this request:

    I list branches on the command line.  These are the branchesI
    care about and I use as anchoring points. I may or may not be on
    one of these main branches.  Please make sure I can view the
    commits on the current branch with respect to what is in these
    other branches.

And to serve that request, the code checks if the current branch is
among the ones listed on the command line, and adds it only if it is
not to the end of one array, which essentially lists the objects.
The reflog mode additionally uses another array to list reflog
messages, which the "--current" code does not add to.  This leaves
one uninitialized slot at the end of the array of reflog messages,
and causes the program to show garbage or segfault.

Catch the unsupported (and meaningless) combination and exit with a
usage error.

There are other combinations of options that are incompatible but
have not been tested.  Add test to cover them while adding coverage
for this new combination.

Reported-by: Gregory David <gregory.david@p1sec.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/show-branch.c
t/t3202-show-branch.sh