Skip to content

Commit 45bc7ce

Browse files
committed
Add --local option
1 parent 0cf7e0c commit 45bc7ce

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

.git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _git_context_graph() {
2323
;;
2424
--*)
2525
__gitcomp "
26-
--add --no-default --list --short --usage --config-add --config-clear
26+
--add --local --no-default --list --short --usage --config-add --config-clear
2727
--all --branches --tags --remotes
2828
--simplify-merges --simplify-by-decoration
2929
--abbrev-commit --no-abbrev-commit --abbrev=

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ showing _only a given branch_ (which might lack context) and showing _all_ branc
1616

1717
## Synopsis
1818

19-
<code><b>git context-graph</b> <i>[--no-default] [-a|--add] [&lt;branch&gt;...]</i></code>
19+
<code><b>git context-graph</b> <i>[--local] [--no-default] [-a|--add] [&lt;branch&gt;...]</i></code>
2020
<code><b>git context-graph</b> <i>[&lt;git-log options&gt;...] [&lt;options&gt;...] [&lt;branch&gt;...] [-- &lt;paths&gt;...]</i></code>
2121

2222
<code><b>git context-graph</b> <i>(-l|--list) [-s|--short] [&lt;branch&gt;]</i></code>
@@ -34,7 +34,7 @@ git log --color --graph --abbrev-commit --decorate --pretty=oneline \
3434
my-branch origin/my-branch main origin/main ...
3535
```
3636

37-
* <code><b>git context-graph</b> <i>[--no-default] [-a|--add] [&lt;branch&gt;...]</i></code>
37+
* <code><b>git context-graph</b> <i>[--local] [--no-default] [-a|--add] [&lt;branch&gt;...]</i></code>
3838
Show graph log of branch, its remote counterparts and default branch.
3939

4040
* <code><b>git context-graph</b> <i>[&lt;git-log options&gt;...] [&lt;options&gt;...] [&lt;branch&gt;...] [-- &lt;paths&gt;...]</i></code>
@@ -63,6 +63,9 @@ git log --color --graph --abbrev-commit --decorate --pretty=oneline \
6363
* `-a`|`--add`
6464
Consider `<branch>` arguments as additional branches (added to current branch).
6565

66+
* `--local`
67+
Show only local branches (ignore remotes).
68+
6669
* `--no-default`
6770
Show only related branches (local and remote), without default branch.
6871

git-context-graph

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ${b}NAME${r}
1212
${u}git-context-graph${r} - Show graph log of branch, its remote counterparts and default branch.
1313
1414
${b}SYNOPSIS${r}
15-
${u}git${r} ${u}context-graph${r} [--no-default] [-a|--add] [<branch>...]
15+
${u}git${r} ${u}context-graph${r} [--local] [--no-default] [-a|--add] [<branch>...]
1616
${u}git${r} ${u}context-graph${r} [<git-log options>...] [<options>...] [<branch>...] [-- <paths>...]
1717
1818
${u}git${r} ${u}context-graph${r} (-l|--list) [-s|--short] [<branch>...]
@@ -28,7 +28,7 @@ ${b}DESCRIPTION${r}
2828
git log --color --graph --abbrev-commit --decorate --pretty=oneline \\
2929
my-branch origin/my-branch main origin/main ...
3030
31-
${u}git${r} ${u}context-graph${r} [--no-default] [-a|--add] [<branch>...]
31+
${u}git${r} ${u}context-graph${r} [--local] [--no-default] [-a|--add] [<branch>...]
3232
Show graph log of branch, its remote counterparts and default branch.
3333
3434
${u}git${r} ${u}context-graph${r} [<git-log options>...] [<options>...] [<branch>...] [-- <paths>...]
@@ -55,6 +55,9 @@ ${b}OPTIONS${r}
5555
-a|--add
5656
Consider <branch> arguments as additional branches (added to current branch).
5757
58+
--local
59+
Show only local branches (ignore remotes).
60+
5861
--no-default
5962
Show only related branches (local and remote), without default branch ('main' / 'master').
6063
@@ -99,11 +102,18 @@ branch_with_remotes() {
99102
return
100103
fi
101104

105+
local ref_pattern
106+
[[ -z $GIT_CG_SHOW_LOCAL_ONLY ]] &&
107+
ref_pattern="refs/**/$short_branch" ||
108+
ref_pattern="refs/heads/$short_branch"
109+
102110
# Branches with same name on all remotes
103111
local same_name_refs;
104-
same_name_refs=$(git for-each-ref --format="%(refname)" "refs/**/$short_branch")
112+
same_name_refs=$(git for-each-ref --format="%(refname)" "$ref_pattern")
105113
echo "$same_name_refs"
106114

115+
[[ -n $GIT_CG_SHOW_LOCAL_ONLY ]] && return
116+
107117
# Remote tracking branch (in case name is different)
108118
local tracking_remote;
109119
tracking_remote=$(git for-each-ref --format='%(upstream)' "$(git rev-parse --symbolic-full-name "$branch" 2> /dev/null)")
@@ -304,6 +314,7 @@ while [[ $# -gt 0 ]]; do
304314
case $1 in
305315
-a|--add) GIT_CG_ADD_TO_CURRENT=1; shift ;;
306316

317+
--local) GIT_CG_SHOW_LOCAL_ONLY=1; shift ;;
307318
--no-default) GIT_CG_SHOW_RELATED_ONLY=1; shift ;;
308319

309320
-l|--list) GIT_CG_LIST=1; shift ;;

0 commit comments

Comments
 (0)