File tree 1 file changed +30
-2
lines changed
1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -279,13 +279,37 @@ function setLastCommandState() {
279
279
GIT_PROMPT_LAST_COMMAND_STATE=$?
280
280
}
281
281
282
+ function we_are_on_repo() {
283
+ if [[ -e " $( git rev-parse --git-dir 2> /dev/null) " ]]; then
284
+ echo 1
285
+ fi
286
+ echo 0
287
+ }
288
+
289
+ function update_old_git_prompt() {
290
+ local in_repo=$( we_are_on_repo)
291
+ if [[ $GIT_PROMPT_OLD_DIR_WAS_GIT = 0 ]]; then
292
+ OLD_GITPROMPT=$PS1
293
+ fi
294
+
295
+ GIT_PROMPT_OLD_DIR_WAS_GIT=$in_repo
296
+ }
297
+
282
298
function setGitPrompt() {
299
+ update_old_git_prompt
300
+
301
+ local repo=` git rev-parse --show-toplevel 2> /dev/null`
302
+ if [[ ! -e " $repo " ]] && [[ " $GIT_PROMPT_ONLY_IN_REPO " = 1 ]]; then
303
+ # we do not permit bash-git-prompt outside git repos, so nothing to do
304
+ PS1=" $OLD_GITPROMPT "
305
+ return
306
+ fi
307
+
283
308
local EMPTY_PROMPT
284
309
local __GIT_STATUS_CMD
285
310
286
311
git_prompt_config
287
312
288
- local repo=` git rev-parse --show-toplevel 2> /dev/null`
289
313
if [[ ! -e " $repo " ]]; then
290
314
PS1=" $EMPTY_PROMPT "
291
315
return
@@ -440,10 +464,14 @@ function gp_install_prompt {
440
464
else
441
465
prompt_callback=" prompt_callback_default"
442
466
fi
443
-
467
+
444
468
if [ -z " $OLD_GITPROMPT " ]; then
445
469
OLD_GITPROMPT=$PS1
446
470
fi
471
+
472
+ if [ -z " $GIT_PROMPT_OLD_DIR_WAS_GIT " ]; then
473
+ GIT_PROMPT_OLD_DIR_WAS_GIT=$( we_are_on_repo)
474
+ fi
447
475
448
476
if [ -z " $PROMPT_COMMAND " ]; then
449
477
PROMPT_COMMAND=setGitPrompt
You can’t perform that action at this time.
0 commit comments