Skip to content

Commit 76b4309

Browse files
rhansengitster
authored andcommitted
git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt
At the beginning of __git_ps1, right after determining that the function is running in pc mode, set PS1 to a plain (undecorated) prompt. This makes it possible to simply return early without having to set PS1 if the prompt should not be decorated. Signed-off-by: Richard Hansen <rhansen@bbn.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c5b9256 commit 76b4309

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

contrib/completion/git-prompt.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ __git_ps1 ()
299299
ps1pc_start="$1"
300300
ps1pc_end="$2"
301301
printf_format="${3:-$printf_format}"
302+
# set PS1 to a plain prompt so that we can
303+
# simply return early if the prompt should not
304+
# be decorated
305+
PS1="$ps1pc_start$ps1pc_end"
302306
;;
303307
0|1) printf_format="${1:-$printf_format}"
304308
;;
@@ -350,10 +354,6 @@ __git_ps1 ()
350354
rev_parse_exit_code="$?"
351355

352356
if [ -z "$repo_info" ]; then
353-
if [ $pcmode = yes ]; then
354-
#In PC mode PS1 always needs to be set
355-
PS1="$ps1pc_start$ps1pc_end"
356-
fi
357357
return
358358
fi
359359

@@ -412,9 +412,6 @@ __git_ps1 ()
412412
else
413413
local head=""
414414
if ! __git_eread "$g/HEAD" head; then
415-
if [ $pcmode = yes ]; then
416-
PS1="$ps1pc_start$ps1pc_end"
417-
fi
418415
return
419416
fi
420417
# is it a symbolic ref?

0 commit comments

Comments
 (0)