Skip to content

Commit 04ce83e

Browse files
committed
Merge branch 'jc/maint-1.6.4-show-branch-default' into maint
* jc/maint-1.6.4-show-branch-default: show-branch: fix segfault when showbranch.default exists
2 parents bb8cccd + 3af1cae commit 04ce83e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

builtin-show-branch.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,15 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
565565
if (!strcmp(var, "showbranch.default")) {
566566
if (!value)
567567
return config_error_nonbool(var);
568-
if (default_alloc <= default_num + 1) {
568+
/*
569+
* default_arg is now passed to parse_options(), so we need to
570+
* mimick the real argv a bit better.
571+
*/
572+
if (!default_num) {
573+
default_alloc = 20;
574+
default_arg = xcalloc(default_alloc, sizeof(*default_arg));
575+
default_arg[default_num++] = "show-branch";
576+
} else if (default_alloc <= default_num + 1) {
569577
default_alloc = default_alloc * 3 / 2 + 20;
570578
default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
571579
}
@@ -692,8 +700,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
692700

693701
/* If nothing is specified, try the default first */
694702
if (ac == 1 && default_num) {
695-
ac = default_num + 1;
696-
av = default_arg - 1; /* ick; we would not address av[0] */
703+
ac = default_num;
704+
av = default_arg;
697705
}
698706

699707
ac = parse_options(ac, av, prefix, builtin_show_branch_options,

t/t3202-show-branch-octopus.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ test_expect_success 'show-branch with more than 8 branches' '
5656
5757
'
5858

59+
test_expect_success 'show-branch with showbranch.default' '
60+
for i in $numbers; do
61+
git config --add showbranch.default branch$i
62+
done &&
63+
git show-branch >out &&
64+
test_cmp expect out
65+
'
66+
5967
test_done

0 commit comments

Comments
 (0)