Skip to content

Commit 1814c5c

Browse files
author
Jonathan Dahan
authored
Merge pull request #296 from duncanbeevers/git-guard
Guard against stderr output in non-git directories
2 parents b02956f + 2d431b9 commit 1814c5c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

functions/geometry_git

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# geometry_git - please see the readme for documentation on all features
22

3+
_geometry_git_guard() {
4+
git rev-parse 2>/dev/null
5+
}
6+
37
geometry_git_stashes() {
8+
_geometry_git_guard || return
49
git rev-parse --quiet --verify refs/stash >/dev/null \
510
&& ansi ${GEOMETRY_GIT_COLOR_STASHES:="144"} ${GEOMETRY_GIT_SYMBOL_STASHES:="●"}
611
}
@@ -16,6 +21,7 @@ geometry_git_time() {
1621
}
1722

1823
geometry_git_branch() {
24+
_geometry_git_guard || return
1925
ansi ${GEOMETRY_GIT_COLOR_BRANCH:-242} $(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD)
2026
}
2127

@@ -29,6 +35,7 @@ geometry_git_status() {
2935
}
3036

3137
geometry_git_rebase() {
38+
_geometry_git_guard || return
3239
local git_dir
3340
git_dir=$(git rev-parse --git-dir)
3441
[[ -d "$git_dir/rebase-merge" ]] || [[ -d "$git_dir/rebase-apply" ]] || return
@@ -51,6 +58,7 @@ geometry_git_remote() {
5158
}
5259

5360
geometry_git_conflicts() {
61+
_geometry_git_guard || return
5462
local _grep
5563
local conflicts conflict_list
5664
local file_count raw_file_count
@@ -78,7 +86,7 @@ geometry_git_conflicts() {
7886
geometry_git() {
7987
(( $+commands[git] )) || return
8088

81-
git rev-parse 2>/dev/null || return
89+
_geometry_git_guard || return
8290

8391
$(git rev-parse --is-bare-repository) \
8492
&& ansi ${GEOMETRY_GIT_COLOR_BARE:=blue} ${GEOMETRY_GIT_SYMBOL_BARE:="⬢"} \

0 commit comments

Comments
 (0)