aboutsummaryrefslogtreecommitdiff
path: root/t/t6300-for-each-ref.sh
diff options
context:
space:
mode:
authorRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>2015-01-05 11:58:55 +0200
committerJunio C Hamano <gitster@pobox.com>2015-01-12 15:10:46 -0800
commitb6160d950c9ef168d0f7d7c9b2812f280e5b88fb (patch)
treeff477be184149287796005aeb522288174d658ae /t/t6300-for-each-ref.sh
parent9a8c2b67cd5a51666f2c0ce3fbbdb08b97b79b3d (diff)
downloadgit-b6160d950c9ef168d0f7d7c9b2812f280e5b88fb.tar.gz
git-b6160d950c9ef168d0f7d7c9b2812f280e5b88fb.tar.xz
for-each-ref: always check stat_tracking_info()'s return value
The code handling %(upstream:track) and %(upstream:trackshort) assumed that it always had a valid branch that had been sanitized earlier in populate_value(), and thus did not check the return value of the call to stat_tracking_info(). While there is indeed some sanitization code that basically corresponds to stat_tracking_info() returning 0 (no base branch set), the function can also return -1 when the base branch did exist but has since then been deleted. In this case, num_ours and num_theirs had undefined values and a call to `git for-each-ref --format="%(upstream:track)"` could print spurious values such as [behind -111794512] [ahead 38881640, behind 5103867] even for repositories with one single commit. Verify stat_tracking_info()'s return value and do not print anything if it returns -1. This behavior also matches the documentation ("has no effect if the ref does not have tracking information associated with it"). Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6300-for-each-ref.sh')
-rwxr-xr-xt/t6300-for-each-ref.sh13
1 files changed, 13 insertions, 0 deletions
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index bda354c1c..c66bf7981 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -334,6 +334,19 @@ test_expect_success 'Check that :track[short] cannot be used with other atoms' '
test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
'
+test_expect_success 'Check that :track[short] works when upstream is invalid' '
+ cat >expected <<-\EOF &&
+
+
+ EOF
+ test_when_finished "git config branch.master.merge refs/heads/master" &&
+ git config branch.master.merge refs/heads/does-not-exist &&
+ git for-each-ref \
+ --format="%(upstream:track)$LF%(upstream:trackshort)" \
+ refs/heads >actual &&
+ test_cmp expected actual
+'
+
cat >expected <<EOF
$(git rev-parse --short HEAD)
EOF