Skip to content

Commit eb443e3

Browse files
fanf2gitster
authored andcommitted
git-prompt: preserve value of $? inside shell prompt
If you have a prompt which displays the command exit status, __git_ps1 without this change corrupts it, although it has the correct value in the parent shell: ~/src/git (master) 0 $ set | grep ^PS1 PS1='\w$(__git_ps1) $? \$ ' ~/src/git (master) 0 $ false ~/src/git (master) 0 $ echo $? 1 ~/src/git (master) 0 $ There is a slightly ugly workaround: ~/src/git (master) 0 $ set | grep ^PS1 PS1='\w$(x=$?; __git_ps1; exit $x) $? \$ ' ~/src/git (master) 0 $ false ~/src/git (master) 1 $ This change makes the workaround unnecessary. Signed-off-by: Tony Finch <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bef111d commit eb443e3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

contrib/completion/git-prompt.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ __git_eread ()
288288
# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
289289
__git_ps1 ()
290290
{
291+
local exit=$?
291292
local pcmode=no
292293
local detached=no
293294
local ps1pc_start='\u@\h:\w '
@@ -511,4 +512,7 @@ __git_ps1 ()
511512
else
512513
printf -- "$printf_format" "$gitstring"
513514
fi
515+
516+
# preserve exit status
517+
return $exit
514518
}

0 commit comments

Comments
 (0)