Skip to content

Commit aa739a0

Browse files
committed
supress OK msg when "fatal: Not a git repository"
1 parent 6411b37 commit aa739a0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

git-branch-status

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ USAGE
4343

4444
### helpers ###
4545

46-
function current_branch() { echo $(git rev-parse --abbrev-ref HEAD) ; }
46+
function get_refs
47+
{
48+
echo "`git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads 2> /dev/null`"
49+
}
50+
51+
function get_status
52+
{
53+
git rev-list --left-right ${local}...${remote} -- 2>/dev/null
54+
}
55+
56+
function current_branch() { echo $(git rev-parse --abbrev-ref HEAD) ; }
4757

4858
function set_filter_or_die
4959
{
@@ -106,7 +116,7 @@ do
106116

107117
# parse local<->remote sync status
108118
if [ $remote ] ; then
109-
status=$(git rev-list --left-right ${local}...${remote} -- 2>/dev/null)
119+
status=$(get_status)
110120
[ $(($?)) -eq 0 ] || continue
111121

112122
n_ahead=$( echo $status | tr " " "\n" | grep -c '^<')
@@ -141,7 +151,7 @@ do
141151
if [ ${#n_behind} -gt $behind_col_w ] ; then behind_col_w=${#n_behind} ; fi ;
142152
if [ ${#remote} -gt $remote_col_w ] ; then remote_col_w=${#remote} ; fi ;
143153

144-
done < <(git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads)
154+
done < <(get_refs)
145155

146156
# compensate for "(ahead )" and "(behind )" to be appended
147157
ahead_col_w=$(( $ahead_col_w + 8 ))
@@ -179,5 +189,7 @@ do
179189
printf "$local_msg$ahead_msg$behind_msg$remote_msg$end_msg\n"
180190
done
181191

182-
# print something if no diffs
183-
if [ "$n_total_differences" == 0 ] ; then echo -e $NO_RESULTS_MSG ; fi ;
192+
# print something if no diffs (and some branches exist in this dir)
193+
if [ "$n_total_differences" == 0 -a "$(get_refs)" ]
194+
then echo -e $NO_RESULTS_MSG
195+
fi

0 commit comments

Comments
 (0)