Skip to content

Commit 99de59c

Browse files
committed
highlight tracking relationship
1 parent 5032f4f commit 99de59c

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
By default, the `git-branch-status` command shows the divergence relationship between branches for which the upstream differs from it's local counterpart.
44

5-
A number of command-line switches exist selecting various output modes to compare any or all local or remote branches.
5+
A number of command-line switches exist, selecting various reports that compare any or all local or remote branches.
6+
67

78
![git-branch-status screenshot][scrot]
89

10+
11+
#### Notes regarding the screenshot above:
12+
13+
* This is showing the exhaustive '--all' report. Other reports are constrained (see 'USAGE' below).
14+
* The "local <-> upstream" section is itemizing all local branches. In this instance:
15+
* The local branch 'deleteme' has no remote tracking branch.
16+
* The local branch 'kd35a' is tracking remote branch 'kd35a/master'.
17+
* The local branch 'knovoselic' is tracking remote branch 'knovoselic/master'.
18+
* The local branch 'master' is tracking remote branch 'origin/master'.
19+
* The "local <-> kd35a" section is itemizing all branches on the 'kd35a' remote. In this instance:
20+
* The local branch 'master' is 2 commits behind and 24 commits ahead of the remote branch 'kd35a/master'.
21+
* The "local <-> knovoselic" section is itemizing all branches on the 'knovoselic' remote. In this instance:
22+
* The local branch 'master' is 4 commits behind and 24 commits ahead of the remote branch 'knovoselic/master'.
23+
* The "local <-> origin" section is itemizing all branches on the 'origin' remote. In this instance:
24+
* The remote branch 'origin/delete-me' is not checked-out locally.
25+
* The remote branch 'origin/master' is tracked by the local branch 'master'.
26+
* The asterisks to the left of local 'master' branch names indicate the current working branch.
27+
* The blue branch names indicate a tracking relationship between a local and it's upstream branch.
28+
* The "local <-> upstream" section relates tracking branches while remote-specific sections relate identically named branches. This distinction determines the semantics of the green "Everything is synchronized" message.
29+
* In the "local <-> upstream" section, this indicates that all local branches which are tracking an upstream are up-to-date with their respective upstream counterparts.
30+
* In remote-specific sections, this indicates that all local branches which have the same name as some branch on this remote are up-to-date with that remote branch.
31+
* In single branch reports, this indicates that the local branch is up-to-date with it's upstream counterpart if it is tracking an upstream; otherwise this will always be shown.
32+
33+
934
```
1035
USAGE:
1136
@@ -70,6 +95,7 @@ EXAMPLES:
7095
| 1999-12-31 tracked | (even) | (even) | 2000-01-01 origin/tracked |
7196
```
7297

98+
7399
_NOTE: please direct comments, bug reports, feature requests, or PRs to one of the upstream repos:_
74100
* [https://github.com/bill-auger/git-branch-status/issues/][github-issues]
75101
* [https://notabug.org/bill-auger/git-branch-status/issues/][notabug-issues]

git-branch-status

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ USAGE_MSG
9999

100100
readonly MAX_COL_W=27 # should be >= 12
101101
readonly CWHITE='\033[0;37m'
102+
readonly CRED='\033[0;31m'
102103
readonly CGREEN='\033[0;32m'
103104
readonly CYELLOW='\033[1;33m'
104-
readonly CRED='\033[0;31m'
105+
readonly CBLUE='\033[1;34m'
105106
readonly CEND='\033[0m'
106107
readonly CDEFAULT=$CWHITE
108+
readonly CTRACKING=$CBLUE
107109
readonly CAHEAD=$CYELLOW
108110
readonly CBEHIND=$CRED
109111
readonly CEVEN=$CGREEN
@@ -139,7 +141,9 @@ declare -a remote_colors=()
139141

140142
function GetRefs # (refs_dir)
141143
{
142-
git for-each-ref --format="%(refname:short) %(upstream:short)" $1 2> /dev/null
144+
refs_dir=$1
145+
146+
git for-each-ref --format="%(refname:short) %(upstream:short)" $refs_dir 2> /dev/null
143147
}
144148

145149
function GetLocalRefs
@@ -167,6 +171,13 @@ function GetCurrentBranch
167171
git rev-parse --abbrev-ref HEAD
168172
}
169173

174+
function GetUpstreamBranch # (local_branch)
175+
{
176+
local_branch=$1
177+
178+
git rev-parse --abbrev-ref $local_branch@{upstream} 2> /dev/null
179+
}
180+
170181
function IsCurrentBranch # (branch_name)
171182
{
172183
branch=$1
@@ -229,6 +240,7 @@ function GenerateReport # (local_branch_name remote_branch_name)
229240
{
230241
local_branch=$1
231242
remote_branch=$2
243+
upstream_branch=$(GetUpstreamBranch $local_branch)
232244
does_local_exist=$(DoesBranchExist $local_branch)
233245

234246
# filter branches per CLI arg
@@ -249,8 +261,9 @@ function GenerateReport # (local_branch_name remote_branch_name)
249261
# filter branches by status
250262
(($SHOW_ALL_UPSTREAM)) || (($n_differences)) || return
251263

252-
# set data for branches with upstream
253-
local_color=$CDEFAULT
264+
# set data for branches with remote counterparts
265+
[ "$remote_branch" == "$upstream_branch" ] && color=$CTRACKING || color=$CDEFAULT
266+
local_color=$color
254267
if (($n_behind))
255268
then behind_msg="(behind$JOIN_CHAR$n_behind)" ; behind_color=$CBEHIND ;
256269
else behind_msg="(even)" ; behind_color=$CEVEN ;
@@ -259,7 +272,7 @@ function GenerateReport # (local_branch_name remote_branch_name)
259272
then ahead_msg="(ahead$JOIN_CHAR$n_ahead)" ; ahead_color=$CAHEAD ;
260273
else ahead_msg="(even)" ; ahead_color=$CEVEN ;
261274
fi
262-
remote_color=$CDEFAULT
275+
remote_color=$color
263276
elif (($does_local_exist)) && [ -z "$remote_branch" ] && (($SHOW_ALL_LOCAL))
264277
then # dummy data for local branches with no upstream counterpart
265278
local_color=$CDEFAULT
@@ -375,9 +388,9 @@ esac
375388
readonly FILTER_BRANCH=$branch
376389
readonly SHOW_DATES=$show_dates
377390
readonly SHOW_ALL=$show_all
378-
readonly SHOW_ALL_LOCAL=$(($show_all + $show_all_local)) # also show branches that have no upstream
379-
readonly SHOW_ALL_UPSTREAM=$(($show_all + $show_all_upstream)) # also show branches that are up to date
380-
readonly SHOW_ALL_REMOTE=$(($show_all + $show_all_remote)) # also show branches that have no local
391+
readonly SHOW_ALL_LOCAL=$(($show_all + $show_all_local)) # show local branches that are not tracking any upstream
392+
readonly SHOW_ALL_UPSTREAM=$(($show_all + $show_all_upstream)) # show local branches that are synchronized with their upstream
393+
readonly SHOW_ALL_REMOTE=$(($show_all + $show_all_remote)) # show all remote branches
381394

382395

383396
# compare local branches status to their upstreams
@@ -390,11 +403,10 @@ PrintReport "local <-> upstream"
390403
# compare other remote branches status to local branches
391404
for remote_repo in `git remote`
392405
do
393-
while read remote_branch ; do
394-
local_branch=${remote_branch#$remote_repo/}
395-
upstream_branch=`git rev-parse --abbrev-ref $local_branch@{upstream} 2> /dev/null`
406+
while read remote_branch
407+
do local_branch=${remote_branch#$remote_repo/}
396408

397-
[ "$remote_branch" != "$upstream_branch" ] && GenerateReport $local_branch $remote_branch
409+
GenerateReport $local_branch $remote_branch
398410
done < <(GetRemoteRefs $remote_repo)
399411

400412
PrintReport "local <-> $remote_repo"

0 commit comments

Comments
 (0)