Skip to content

Commit d613b3e

Browse files
committed
tolerate remotes that have not yet been fetched
1 parent 7ac60c0 commit d613b3e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

git-branch-status

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ readonly TTY_W_MSG="TTY must be wider than $MIN_TTY_W chars"
149149
readonly INVALID_BRANCH_MSG="No such branch:"
150150
readonly INVALID_LOCAL_BRANCH_MSG="No such local branch:"
151151
readonly NO_RESULTS_MSG="Nothing to compare"
152+
readonly NO_REFS_MSG="(No data)"
152153
readonly LOCALS_SYNCED_MSG="All tracking branches are synchronized with their upstreams"
153154
readonly BRANCH_SYNCED_MSG="This tracking branch is synchronized with it's upstream"
154155
readonly UNTRACKED_SYNCHED_MSG="These branches are synchronized with no tracking relationship"
@@ -428,7 +429,7 @@ function GenerateReport # (base_branch compare_branch)
428429
WereAnyCompared=1
429430

430431
# filter branches by status
431-
(( $SHOW_ALL_SYNCED )) || (( $n_divergences )) || return
432+
(( $SHOW_ALL_SYNCED )) || (( $n_divergences > 0 )) || return
432433

433434
# set data for branches with remote counterparts or arbitrary branches
434435
(($is_tracked_branch)) && color=$CTRACKING || color=$CDEFAULT
@@ -484,31 +485,39 @@ function PrintReport # (table_header_line synchronized_msg)
484485
local synchronized_msg=$2
485486
local available_w=$(( $(CurrentTtyW) - $AheadW - $BehindW - $ALL_PADDING_W ))
486487
local n_results=${#LocalMsgs[@]}
487-
local all_in_sync
488+
local are_all_in_sync
488489
local result_n
489-
(( $WereAnyCompared )) && !(( $WereAnyDivergences )) && all_in_sync=1 || all_in_sync=0
490-
491-
(( $n_results == 0 )) && (( $all_in_sync == 0 )) && EXIT "$NO_RESULTS_MSG"
490+
(( $WereAnyCompared )) && !(( $WereAnyDivergences )) && are_all_in_sync=1 || are_all_in_sync=0
492491

493492
# truncate column widths to fit
494493
while (( $LocalW + $RemoteW > $available_w ))
495494
do (( $LocalW >= $RemoteW )) && LocalW=$(( $LocalW - 1 ))
496495
(( $LocalW <= $RemoteW )) && RemoteW=$(( $RemoteW - 1 ))
497496
done
498497

498+
# print comparison header
499+
if (( $are_all_in_sync ))
500+
then printf "\n$CGREEN$MARGIN_PAD$table_header_line$CEND\n"
501+
elif (( $n_results > 0 ))
502+
then printf "\n$MARGIN_PAD$table_header_line\n"
503+
else printf "\n$CRED$MARGIN_PAD$table_header_line$CEND$MARGIN_PAD"
504+
fi
505+
499506
# pretty print divergence results
500-
printf "\n$MARGIN_PAD$table_header_line\n"
501-
if (( $n_results ))
507+
if (( $n_results > 0 ))
502508
then local rule_w=$(( $LocalW + $BehindW + $AheadW + $RemoteW + $INNER_PADDING_W ))
509+
503510
PrintHRule $rule_w
504511
for (( result_n = 0 ; result_n < $n_results ; ++result_n ))
505512
do PrintReportLine
506513
done
507514
PrintHRule $rule_w
515+
else ([ -z "$(GetRemoteRefs $remote_repo)" ] && printf "$CRED$NO_REFS_MSG$CEND\n") || \
516+
(!(( $are_all_in_sync )) && echo "$NO_RESULTS_MSG" )
508517
fi
509518

510519
# print "synchronized" message if all compared upstreams had no divergence
511-
if (( $all_in_sync ))
520+
if (( $are_all_in_sync ))
512521
then local l_border="$DELIM " ; local r_border=" $DELIM" ;
513522
local borders_pad_w=$(( ${#l_border} + ${#r_border} ))
514523
local wrap_w=$(( $(CurrentTtyW) - $MARGINS_PAD_W - $borders_pad_w ))

0 commit comments

Comments
 (0)