Merge branch 'zh/ref-filter-push-remote-fix'

The handling of "%(push)" formatting element of "for-each-ref" and
friends was broken when the same codepath started handling
"%(push:<what>)", which has been corrected.

* zh/ref-filter-push-remote-fix:
  ref-filter: fix read invalid union member bug
This commit is contained in:
Junio C Hamano 2021-05-20 08:55:00 +09:00
commit 36a255acd1
2 changed files with 20 additions and 1 deletions

View File

@ -1730,7 +1730,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
else
v->s = xstrdup("");
continue;
} else if (atom->u.remote_ref.push) {
} else if (!strcmp(atom->name, "push") || starts_with(atom->name, "push:")) {
const char *branch_name;
v->s = xstrdup("");
if (!skip_prefix(ref->refname, "refs/heads/",

View File

@ -117,6 +117,25 @@ test_expect_success '%(color) must fail' '
test_must_fail git for-each-ref --format="%(color)%(refname)"
'
test_expect_success '%(color:#aa22ac) must succeed' '
test_when_finished rm -rf test &&
git init test &&
(
cd test &&
test_commit initial &&
git branch -M main &&
cat >expect <<-\EOF &&
refs/heads/main
refs/tags/initial
EOF
git remote add origin nowhere &&
git config branch.main.remote origin &&
git config branch.main.merge refs/heads/main &&
git for-each-ref --format="%(color:#aa22ac)%(refname)" >actual &&
test_cmp expect actual
)
'
test_expect_success 'left alignment is default' '
cat >expect <<-\EOF &&
refname is refs/heads/main |refs/heads/main