• R
    for-each-ref: always check stat_tracking_info()'s return value · b6160d95
    Raphael Kubo da Costa 提交于
    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: NEric Sunshine <sunshine@sunshineco.com>
    Helped-by: NJeff King <peff@peff.net>
    Signed-off-by: NRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    b6160d95
t6300-for-each-ref.sh 15.7 KB