Skip to content

Commit 9920c71

Browse files
committed
Merge branch 'tf/prompt-preserve-exit-status'
Using the exit status of the last command in the prompt, e.g. PS1='$(__git_ps1) $? ', did not work well because the helper function stomped on the exit status. * tf/prompt-preserve-exit-status: git-prompt: preserve value of $? in all cases
2 parents e1ef7d1 + 6babe76 commit 9920c71

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

contrib/completion/git-prompt.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ __git_eread ()
293293
# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
294294
__git_ps1 ()
295295
{
296+
# preserve exit status
296297
local exit=$?
297298
local pcmode=no
298299
local detached=no
@@ -312,7 +313,7 @@ __git_ps1 ()
312313
;;
313314
0|1) printf_format="${1:-$printf_format}"
314315
;;
315-
*) return
316+
*) return $exit
316317
;;
317318
esac
318319

@@ -360,7 +361,7 @@ __git_ps1 ()
360361
rev_parse_exit_code="$?"
361362

362363
if [ -z "$repo_info" ]; then
363-
return
364+
return $exit
364365
fi
365366

366367
local short_sha
@@ -380,7 +381,7 @@ __git_ps1 ()
380381
[ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
381382
git check-ignore -q .
382383
then
383-
return
384+
return $exit
384385
fi
385386

386387
local r=""
@@ -426,7 +427,7 @@ __git_ps1 ()
426427
else
427428
local head=""
428429
if ! __git_eread "$g/HEAD" head; then
429-
return
430+
return $exit
430431
fi
431432
# is it a symbolic ref?
432433
b="${head#ref: }"
@@ -523,6 +524,5 @@ __git_ps1 ()
523524
printf -- "$printf_format" "$gitstring"
524525
fi
525526

526-
# preserve exit status
527527
return $exit
528528
}

0 commit comments

Comments
 (0)