Skip to content

Commit 36a255a

Browse files
committed
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
2 parents bdff041 + 1e1c4c5 commit 36a255a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
17301730
else
17311731
v->s = xstrdup("");
17321732
continue;
1733-
} else if (atom->u.remote_ref.push) {
1733+
} else if (!strcmp(atom->name, "push") || starts_with(atom->name, "push:")) {
17341734
const char *branch_name;
17351735
v->s = xstrdup("");
17361736
if (!skip_prefix(ref->refname, "refs/heads/",

t/t6302-for-each-ref-filter.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ test_expect_success '%(color) must fail' '
117117
test_must_fail git for-each-ref --format="%(color)%(refname)"
118118
'
119119

120+
test_expect_success '%(color:#aa22ac) must succeed' '
121+
test_when_finished rm -rf test &&
122+
git init test &&
123+
(
124+
cd test &&
125+
test_commit initial &&
126+
git branch -M main &&
127+
cat >expect <<-\EOF &&
128+
refs/heads/main
129+
refs/tags/initial
130+
EOF
131+
git remote add origin nowhere &&
132+
git config branch.main.remote origin &&
133+
git config branch.main.merge refs/heads/main &&
134+
git for-each-ref --format="%(color:#aa22ac)%(refname)" >actual &&
135+
test_cmp expect actual
136+
)
137+
'
138+
120139
test_expect_success 'left alignment is default' '
121140
cat >expect <<-\EOF &&
122141
refname is refs/heads/main |refs/heads/main

0 commit comments

Comments
 (0)