Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 023079f

Browse files
committed
Merge pull request #27 from phatblat/pull/suppress-ps1-errors
Suppress dirty marker and errors building PS1 when outside a repo
2 parents 7b82d95 + 010de87 commit 023079f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

git-sh.bash

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ ANSI_RESET="\001$(git config --get-color "" "reset")\002"
183183

184184
# detect whether the tree is in a dirty state.
185185
_git_dirty() {
186-
local dirty_marker="`git config gitsh.dirty || echo ' *'`"
186+
if ! git rev-parse --verify HEAD >/dev/null 2>&1; then
187+
return 0
188+
fi
189+
local dirty_marker="`git config gitsh.dirty 2>/dev/null || echo ' *'`"
187190

188191
if ! git diff --quiet 2>/dev/null ; then
189192
_git_apply_color "$dirty_marker" "color.sh.dirty" "red"
@@ -199,7 +202,7 @@ _git_dirty_stash() {
199202
if ! git rev-parse --verify refs/stash >/dev/null 2>&1; then
200203
return 0
201204
fi
202-
local dirty_stash_marker="`git config gitsh.dirty-stash || echo ' $'`"
205+
local dirty_stash_marker="`git config gitsh.dirty-stash 2>/dev/null || echo ' $'`"
203206
_git_apply_color "$dirty_stash_marker" "color.sh.dirty-stash" "red"
204207
}
205208

@@ -222,7 +225,7 @@ _git_workdir() {
222225

223226
# detect if the repository is in a special state (rebase or merge)
224227
_git_repo_state() {
225-
local git_dir="$(git rev-parse --show-cdup).git"
228+
local git_dir="$(git rev-parse --show-cdup 2>/dev/null).git"
226229
if test -d "$git_dir/rebase-merge" -o -d "$git_dir/rebase-apply"; then
227230
local state_marker="(rebase)"
228231
elif test -f "$git_dir/MERGE_HEAD"; then

0 commit comments

Comments
 (0)