branch: report invalid tracking branch as gone
commitf2e087395b78d5828af400072c1b621e1a373be4
authorJiang Xin <worldhello.net@gmail.com>
Mon, 26 Aug 2013 07:02:48 +0000 (26 15:02 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Aug 2013 16:05:22 +0000 (26 09:05 -0700)
treea9d657efa55e3c856fa4abb549b3066f5cc82f3c
parent425df881e08bed7a8fcc9a23f452cff792f9ec6c
branch: report invalid tracking branch as gone

Command "git branch -vv" will report tracking branches, but invalid
tracking branches are also reported. This is because the function
stat_tracking_info() can not distinguish invalid tracking branch
from other cases which it would not like to report, such as
there is no upstream settings at all, or nothing is changed between
one branch and its upstream.

Junio suggested missing upstream should be reported [1] like:

    $ git branch -v -v
      master    e67ac84 initial
    * topic     3fc0f2a [topicbase: gone] topic

    $ git status
    # On branch topic
    # Your branch is based on 'topicbase', but the upstream is gone.
    #   (use "git branch --unset-upstream" to fixup)
    ...

    $ git status -b -s
    ## topic...topicbase [gone]
    ...

In order to do like that, we need to distinguish these three cases
(i.e. no tracking, with configured but no longer valid tracking, and
with tracking) in function stat_tracking_info(). So the refactored
function stat_tracking_info() has three return values: -1 (with "gone"
base), 0 (no base), and 1 (with base).

If the caller does not like to report tracking info when nothing
changed between the branch and its upstream, simply checks if
num_theirs and num_ours are both 0.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/231830/focus=232288

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
remote.c
t/t6040-tracking-info.sh
wt-status.c