Skip to content

Commit 401a317

Browse files
committed
Merge branch 'rc/for-each-ref-tracking'
* rc/for-each-ref-tracking: for-each-ref: always check stat_tracking_info()'s return value
2 parents 63a0e83 + b6160d9 commit 401a317

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

builtin/for-each-ref.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,10 @@ static void populate_value(struct refinfo *ref)
717717
starts_with(name, "upstream")) {
718718
char buf[40];
719719

720-
stat_tracking_info(branch, &num_ours, &num_theirs);
720+
if (stat_tracking_info(branch, &num_ours,
721+
&num_theirs) != 1)
722+
continue;
723+
721724
if (!num_ours && !num_theirs)
722725
v->s = "";
723726
else if (!num_ours) {
@@ -735,7 +738,11 @@ static void populate_value(struct refinfo *ref)
735738
} else if (!strcmp(formatp, "trackshort") &&
736739
starts_with(name, "upstream")) {
737740
assert(branch);
738-
stat_tracking_info(branch, &num_ours, &num_theirs);
741+
742+
if (stat_tracking_info(branch, &num_ours,
743+
&num_theirs) != 1)
744+
continue;
745+
739746
if (!num_ours && !num_theirs)
740747
v->s = "=";
741748
else if (!num_ours)

t/t6300-for-each-ref.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ test_expect_success 'Check that :track[short] cannot be used with other atoms' '
334334
test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
335335
'
336336

337+
test_expect_success 'Check that :track[short] works when upstream is invalid' '
338+
cat >expected <<-\EOF &&
339+
340+
341+
EOF
342+
test_when_finished "git config branch.master.merge refs/heads/master" &&
343+
git config branch.master.merge refs/heads/does-not-exist &&
344+
git for-each-ref \
345+
--format="%(upstream:track)$LF%(upstream:trackshort)" \
346+
refs/heads >actual &&
347+
test_cmp expected actual
348+
'
349+
337350
cat >expected <<EOF
338351
$(git rev-parse --short HEAD)
339352
EOF

0 commit comments

Comments
 (0)