Skip to content

Commit cacb997

Browse files
committed
housekeeping
1 parent d3e50c3 commit cacb997

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ EXAMPLES:
5858
| feature-branch | (even) | (ahead 2) | origin/feature-branch |
5959
| master | (behind 1) | (even) | origin/master |
6060
61-
# compare two arbitrary branches (either local and either remote)
61+
# compare two arbitrary branches - local or remote
6262
$ git-branch-status local-arbitrary-branch fork/arbitrary-branch
6363
| local-arbitrary-branch | (even) | (ahead 1) | fork/arbitrary-branch |
6464
$ git-branch-status fork/arbitrary-branch local-arbitrary-branch
6565
| fork/arbitrary-branch | (behind 1) | (even) | local-arbitrary-branch |
6666
67-
# show all branches - including those synchronized, non-tracking, or not checked-out
67+
# show all branches - local and remote, regardless of state or relationship
6868
$ git-branch-status -a
6969
$ git-branch-status --all
70-
| master | (even) | (ahead 1) | origin/master |
70+
*| master | (even) | (ahead 1) | origin/master |
7171
| tracked-branch | (even) | (even) | origin/tracked-branch |
7272
| (no local) | n/a | n/a | origin/untracked-branch |
7373
| local-branch | n/a | n/a | (no upstream) |
@@ -77,7 +77,7 @@ EXAMPLES:
7777
# show the current branch
7878
$ git-branch-status -b
7979
$ git-branch-status --branch
80-
| current-branch | (even) | (ahead 2) | origin/current-branch |
80+
*| current-branch | (even) | (ahead 2) | origin/current-branch |
8181
8282
# show a specific branch
8383
$ git-branch-status specific-branch
@@ -98,7 +98,7 @@ EXAMPLES:
9898
# show all local branches - including those synchronized or non-tracking
9999
$ git-branch-status -l
100100
$ git-branch-status --local
101-
| master | (even) | (ahead 1) | origin/master |
101+
*| master | (even) | (ahead 1) | origin/master |
102102
| tracked-branch | (even) | (even) | origin/tracked-branch |
103103
| local-branch | n/a | n/a | (no upstream) |
104104
@@ -111,9 +111,9 @@ EXAMPLES:
111111
# show all branches with timestamps (like -a -d)
112112
$ git-branch-status -v
113113
$ git-branch-status --verbose
114-
| 1999-12-31 local | n/a | n/a | (no upstream) |
115-
| 1999-12-31 master | (behind 1) | (even) | 2000-01-01 origin/master |
116-
| 1999-12-31 tracked | (even) | (even) | 2000-01-01 origin/tracked |
114+
| 1999-12-31 master | (behind 1) | (even) | 2000-01-01 origin/master |
115+
| 1999-12-31 tracked | (even) | (even) | 2000-01-01 origin/tracked |
116+
*| 1999-12-31 local-wip | n/a | n/a | (no upstream) |
117117
```
118118

119119

git-branch-status

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright 2011 Jehiah Czebotar <https://github.com/jehiah>
66
# Copyright 2013 Fredrik Strandin <https://github.com/kd35a>
77
# Copyright 2014 Kristijan Novoselić <https://github.com/knovoselic>
8-
# Copyright 2014-2018 bill-auger <https://github.com/bill-auger>
8+
# Copyright 2014-2020 bill-auger <https://github.com/bill-auger>
99
#
1010
# git-branch-status is free software: you can redistribute it and/or modify
1111
# it under the terms of the GNU General Public License version 3
@@ -53,16 +53,16 @@ EXAMPLES:
5353
| feature-branch | (even) | (ahead 2) | origin/feature-branch |
5454
| master | (behind 1) | (even) | origin/master |
5555
56-
# compare two arbitrary branches (either local and either remote)
56+
# compare two arbitrary branches - local or remote
5757
$ git-branch-status local-arbitrary-branch fork/arbitrary-branch
5858
| local-arbitrary-branch | (even) | (ahead 1) | fork/arbitrary-branch |
5959
$ git-branch-status fork/arbitrary-branch local-arbitrary-branch
6060
| fork/arbitrary-branch | (behind 1) | (even) | local-arbitrary-branch |
6161
62-
# show all branches - including those synchronized, non-tracking, or not checked-out
62+
# show all branches - local and remote, regardless of state or relationship
6363
$ git-branch-status -a
6464
$ git-branch-status --all
65-
| master | (even) | (ahead 1) | origin/master |
65+
*| master | (even) | (ahead 1) | origin/master |
6666
| tracked-branch | (even) | (even) | origin/tracked-branch |
6767
| (no local) | n/a | n/a | origin/untracked-branch |
6868
| local-branch | n/a | n/a | (no upstream) |
@@ -72,7 +72,7 @@ EXAMPLES:
7272
# show the current branch
7373
$ git-branch-status -b
7474
$ git-branch-status --branch
75-
| current-branch | (even) | (ahead 2) | origin/current-branch |
75+
*| current-branch | (even) | (ahead 2) | origin/current-branch |
7676
7777
# show a specific branch
7878
$ git-branch-status specific-branch
@@ -93,7 +93,7 @@ EXAMPLES:
9393
# show all local branches - including those synchronized or non-tracking
9494
$ git-branch-status -l
9595
$ git-branch-status --local
96-
| master | (even) | (ahead 1) | origin/master |
96+
*| master | (even) | (ahead 1) | origin/master |
9797
| tracked-branch | (even) | (even) | origin/tracked-branch |
9898
| local-branch | n/a | n/a | (no upstream) |
9999
@@ -106,9 +106,9 @@ EXAMPLES:
106106
# show all branches with timestamps (like -a -d)
107107
$ git-branch-status -v
108108
$ git-branch-status --verbose
109-
| 1999-12-31 local | n/a | n/a | (no upstream) |
110-
| 1999-12-31 master | (behind 1) | (even) | 2000-01-01 origin/master |
111-
| 1999-12-31 tracked | (even) | (even) | 2000-01-01 origin/tracked |
109+
| 1999-12-31 master | (behind 1) | (even) | 2000-01-01 origin/master |
110+
| 1999-12-31 tracked | (even) | (even) | 2000-01-01 origin/tracked |
111+
*| 1999-12-31 local-wip | n/a | n/a | (no upstream) |
112112
USAGE_MSG
113113

114114

@@ -131,7 +131,7 @@ readonly MARGIN_PAD_W=2
131131
readonly MARGINS_PAD_W=$(( $MARGIN_PAD_W * 2 ))
132132
readonly ALL_PADDING_W=$(( $INNER_PADDING_W + $MARGINS_PAD_W ))
133133
readonly MAX_DIVERGENCE_W=12 # e.g. "(behind 999)"
134-
readonly MIN_TTY_W=60 # ASSERT: (0 < ($ALL_PADDING_W + (MAX_DIVERGENCE_W * 2)) <= $MIN_TTY_W)
134+
readonly MIN_TTY_W=60 # ASSERT: (0 < (ALL_PADDING_W + (MAX_DIVERGENCE_W * 2)) <= MIN_TTY_W)
135135
readonly MARGIN_PAD=$(printf "%$(( $MARGIN_PAD_W ))s")
136136
readonly CWHITE='\033[0;37m'
137137
readonly CRED='\033[0;31m'
@@ -196,23 +196,23 @@ declare -a RemoteColors=()
196196

197197
## helpers ##
198198

199-
function AssertIsValidRepo
199+
AssertIsValidRepo()
200200
{
201201
[ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ] || \
202202
! (( $(AssertIsNotBareRepo) )) && echo 1 || echo 0
203203
}
204204

205-
function AssertHasCommits
205+
AssertHasCommits()
206206
{
207207
[ "$(git cat-file -t HEAD 2> /dev/null)" ] && echo 1 || echo 0
208208
}
209209

210-
function AssertIsNotBareRepo
210+
AssertIsNotBareRepo()
211211
{
212212
[ "$(git rev-parse --is-bare-repository 2> /dev/null)" != 'true' ] && echo 1 || echo 0
213213
}
214214

215-
function GetRefs # (refs_dir)
215+
GetRefs() # (refs_dir)
216216
{
217217
local refs_dir=$1
218218
local fmt='%(refname:short) %(upstream:short)'
@@ -221,39 +221,39 @@ function GetRefs # (refs_dir)
221221
git for-each-ref --format="$fmt" $sort $refs_dir 2> /dev/null
222222
}
223223

224-
function GetLocalRefs
224+
GetLocalRefs()
225225
{
226226
GetRefs refs/heads
227227
}
228228

229-
function GetRemoteRefs # (remote_repo_name)
229+
GetRemoteRefs() # (remote_repo_name)
230230
{
231231
local remote_repo=$1
232232

233233
GetRefs refs/remotes/$remote_repo
234234
}
235235

236-
function GetStatus # (base_commit compare_commit)
236+
GetStatus() # (base_commit compare_commit)
237237
{
238238
local base_commit=$1
239239
local compare_commit=$2
240240

241241
git rev-list --left-right ${base_commit}...${compare_commit} -- 2>/dev/null
242242
}
243243

244-
function GetCurrentBranch
244+
GetCurrentBranch()
245245
{
246246
git rev-parse --abbrev-ref HEAD
247247
}
248248

249-
function GetUpstreamBranch # (local_branch)
249+
GetUpstreamBranch() # (local_branch)
250250
{
251251
local local_branch=$1
252252

253253
git rev-parse --abbrev-ref $local_branch@{upstream} 2> /dev/null
254254
}
255255

256-
function IsCurrentBranch # (branch_name)
256+
IsCurrentBranch() # (branch_name)
257257
{
258258
local branch=$1
259259
local this_branch=$(AppendHeadDate $branch)
@@ -262,15 +262,15 @@ function IsCurrentBranch # (branch_name)
262262
[ "$this_branch" == "$current_branch" ] && echo 1 || echo 0
263263
}
264264

265-
function IsLocalBranch # (branch_name)
265+
IsLocalBranch() # (branch_name)
266266
{
267267
local branch=$1
268268
local is_local_branch=$(git branch -a | grep -E "^.* $branch$")
269269

270270
[ "$is_local_branch" ] && echo 1 || echo 0
271271
}
272272

273-
function IsTrackedBranch # (base_branch_name compare_branch_name)
273+
IsTrackedBranch() # (base_branch_name compare_branch_name)
274274
{
275275
local base_branch=$1
276276
local compare_branch=$2
@@ -279,15 +279,15 @@ function IsTrackedBranch # (base_branch_name compare_branch_name)
279279
[ "$compare_branch" == "$upstream_branch" ] && echo 1 || echo 0
280280
}
281281

282-
function DoesBranchExist # (branch_name)
282+
DoesBranchExist() # (branch_name)
283283
{
284284
local branch=$1
285285
local is_known_branch=$(git branch -a | grep -E "^.* (remotes\/)?$branch$")
286286

287287
[ "$is_known_branch" ] && echo 1 || echo 0
288288
}
289289

290-
function AppendHeadDate # (commit_ref)
290+
AppendHeadDate() # (commit_ref)
291291
{
292292
local commit=$1
293293
local author_date=$(git log -n 1 --format=format:"%ai" $commit 2> /dev/null)
@@ -298,23 +298,23 @@ function AppendHeadDate # (commit_ref)
298298
echo $date$commit
299299
}
300300

301-
function CurrentTtyW
301+
CurrentTtyW()
302302
{
303303
local tty_dims=$(stty -F /dev/tty size 2> /dev/null || stty -f /dev/tty size 2> /dev/null)
304304
local tty_w=$(echo $tty_dims | cut -d ' ' -f 2)
305305

306306
(( $tty_w )) && echo "$tty_w" || echo "$MIN_TTY_W"
307307
}
308308

309-
function PrintHRule # (rule_width)
309+
PrintHRule() # (rule_width)
310310
{
311311
local rule_w=$1
312312
local h_rule="$(dd if=/dev/zero bs=$rule_w count=1 2> /dev/null | tr '\0' $HRULE_CHAR)"
313313

314314
echo "$MARGIN_PAD$h_rule"
315315
}
316316

317-
function EXIT # (exit_msg exit_status)
317+
Exit() # (exit_msg exit_status)
318318
{
319319
local exit_msg=$1
320320
local exit_status=$2
@@ -328,7 +328,7 @@ function EXIT # (exit_msg exit_status)
328328

329329
## business ##
330330

331-
function Init # (cli_args)
331+
Init() # (cli_args)
332332
{
333333
local show_dates=0
334334
local show_all=0
@@ -343,21 +343,21 @@ function Init # (cli_args)
343343
'-a'|'--all' ) show_all=1 ;;
344344
'-b'|'--branch' ) [ "$2" ] && branch_a="$2" || branch_a=$(GetCurrentBranch) ;;
345345
'-d'|'--dates' ) branch_a="$2" ; branch_b="$3" ; show_dates=1 ;;
346-
'-h'|'--help' ) EXIT "$USAGE" $EXIT_SUCCESS ;;
346+
'-h'|'--help' ) Exit "$USAGE" $EXIT_SUCCESS ;;
347347
'-l'|'--local' ) show_all_local=1 ; show_all_synced=1 ; ;;
348348
'-r'|'--remotes' ) show_all_remote=1 ; show_all_synced=1 ; ;;
349349
'-v'|'--verbose' ) show_all=1 ; show_dates=1 ; ;;
350350
* ) branch_a="$1" ; branch_b="$2" ; ;;
351351
esac
352352

353353
# sanity checks
354-
(( $(AssertIsValidRepo ) )) || EXIT "$NOT_REPO_ERR"
355-
(( $(AssertIsNotBareRepo) )) || EXIT "$BARE_REPO_MSG"
356-
(( $(AssertHasCommits ) )) || EXIT "$NO_COMMITS_MSG"
357-
(( $(CurrentTtyW) >= $MIN_TTY_W )) || EXIT "$TTY_W_MSG"
358-
[ -z "$branch_a" ] || (($(DoesBranchExist $branch_a))) || EXIT "$INVALID_BRANCH_MSG '$branch_a'"
359-
[ -z "$branch_b" ] || (($(DoesBranchExist $branch_b))) || EXIT "$INVALID_BRANCH_MSG '$branch_b'"
360-
[ -z "$branch_a" ] || (($(IsLocalBranch $branch_a))) || [ "$branch_b" ] || EXIT "$INVALID_LOCAL_BRANCH_MSG '$branch_a'"
354+
(( $(AssertIsValidRepo ) )) || Exit "$NOT_REPO_ERR"
355+
(( $(AssertIsNotBareRepo) )) || Exit "$BARE_REPO_MSG"
356+
(( $(AssertHasCommits ) )) || Exit "$NO_COMMITS_MSG"
357+
(( $(CurrentTtyW) >= $MIN_TTY_W )) || Exit "$TTY_W_MSG"
358+
[ -z "$branch_a" ] || (($(DoesBranchExist $branch_a))) || Exit "$INVALID_BRANCH_MSG '$branch_a'"
359+
[ -z "$branch_b" ] || (($(DoesBranchExist $branch_b))) || Exit "$INVALID_BRANCH_MSG '$branch_b'"
360+
[ -z "$branch_a" ] || (($(IsLocalBranch $branch_a))) || [ "$branch_b" ] || Exit "$INVALID_LOCAL_BRANCH_MSG '$branch_a'"
361361
[ -z "$branch_a" ] || show_all_local=1 # force "no upstream" message for non-tracking branches
362362

363363
readonly SHOW_DATES=$show_dates
@@ -368,7 +368,7 @@ function Init # (cli_args)
368368
readonly COMPARE_BRANCH=$branch_b
369369
}
370370

371-
function FetchRemotes
371+
FetchRemotes()
372372
{
373373
if (( ${FETCH_PERIOD} >= 0 ))
374374
then local now_ts=$(date +%s)
@@ -381,7 +381,7 @@ function FetchRemotes
381381
fi
382382
}
383383

384-
function GenerateReports
384+
GenerateReports()
385385
{
386386
if [ "$COMPARE_BRANCH" ]
387387
then CustomReport $(IsTrackedBranch $FILTER_BRANCH $COMPARE_BRANCH)
@@ -390,7 +390,7 @@ function GenerateReports
390390
fi
391391
}
392392

393-
function CustomReport # (is_tracked_branch)
393+
CustomReport() # (is_tracked_branch)
394394
{
395395
local is_tracked_branch=$1
396396
local synchronized_msg
@@ -401,7 +401,7 @@ function CustomReport # (is_tracked_branch)
401401
PrintReport "$FILTER_BRANCH <-> $COMPARE_BRANCH" "$synchronized_msg"
402402
}
403403

404-
function LocalReport
404+
LocalReport()
405405
{
406406
local synchronized_msg
407407
[ "$FILTER_BRANCH" ] && synchronized_msg="$BRANCH_SYNCED_MSG" || synchronized_msg="$LOCALS_SYNCED_MSG"
@@ -411,7 +411,7 @@ function LocalReport
411411
PrintReport "local <-> upstream" "$synchronized_msg"
412412
}
413413

414-
function RemoteReport
414+
RemoteReport()
415415
{
416416
local synchronized_msg="$REMOTES_SYNCED_MSG"
417417
local remote_repo
@@ -428,7 +428,7 @@ function RemoteReport
428428
done
429429
}
430430

431-
function GenerateReport # (base_branch compare_branch)
431+
GenerateReport() # (base_branch compare_branch)
432432
{
433433
local base_branch=$1
434434
local compare_branch=$2
@@ -506,7 +506,7 @@ function GenerateReport # (base_branch compare_branch)
506506
if [ ${#remote_msg} -gt $RemoteW ] ; then RemoteW=${#remote_msg} ; fi ;
507507
}
508508

509-
function PrintReport # (table_header_line synchronized_msg)
509+
PrintReport() # (table_header_line synchronized_msg)
510510
{
511511
local table_header_line=$1
512512
local synchronized_msg=$2
@@ -573,7 +573,7 @@ function PrintReport # (table_header_line synchronized_msg)
573573
Reset
574574
}
575575

576-
function PrintReportLine
576+
PrintReportLine()
577577
{
578578
# select data
579579
local local_msg=$( echo ${LocalMsgs[ $result_n]} | sed "$JOIN_REGEX")
@@ -605,7 +605,7 @@ function PrintReportLine
605605
printf "$local_msg$behind_msg$ahead_msg$remote_msg$end_msg\n"
606606
}
607607

608-
function Reset
608+
Reset()
609609
{
610610
WereAnyDivergences=0
611611
WereAnyCompared=0

0 commit comments

Comments
 (0)