Skip to content

Commit 410fd05

Browse files
committed
GIT_PROMPT_SHOW_UNTRACKED_FILES=no was not working correctly
* Fixed the bug, than GIT_SHOW_UNTRACKED_FILES=no was not respected * Renamed GIT_SHOW_UNTRACKED_FILES to GIT_PROMPT_SHOW_UNTRACKED_FILES as this is more consistent to the other environment variables * GIT_PROMPT_SHOW_UNTRACKED_FILES can be now also set on a per repository basis in .bash-git-rc * Updated README Fixes #215 and 216
1 parent 2d9ec22 commit 410fd05

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
124124
# GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status
125125

126126
# GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch
127-
# GIT_SHOW_UNTRACKED_FILES=all # can be no, normal or all; determines counting of untracked files
128-
127+
# GIT_PROMPT_SHOW_UNTRACKED_FILES=all # can be no, normal or all; determines counting of untracked files
128+
129129
# GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10
130130

131131
# GIT_PROMPT_START=... # uncomment for custom prompt start sequence
@@ -137,7 +137,7 @@ git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt
137137
source ~/.bash-git-prompt/gitprompt.sh
138138
```
139139

140-
You can set the `GIT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of
140+
You can set the `GIT_PROMPT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of
141141
untracked files in your repository. This can be the case for build systems that put their build artifacts in
142142
the subdirectory structure of the git repository.
143143

@@ -202,7 +202,7 @@ If you use a custom theme in `.git-prompt-colors.sh`, please set `GIT_PROMPT_THE
202202
and end of the prompt by setting `GIT_PROMPT_START` and `GIT_PROMPT_END`
203203
before you source the `gitprompt.sh`.
204204

205-
- The current git repo information is obtained by the script `gitstatus.sh`.
205+
- The current git repo information is obtained by the script `gitstatus.sh`.
206206
- You can define `prompt_callback` function to tweak your prompt dynamically.
207207

208208
```sh
@@ -247,6 +247,11 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo
247247
- You can also ignore a repository completely by creating a file named ``.bash-git-rc`` with the
248248
content ``GIT_PROMPT_IGNORE=1`` in the root of your git repository.
249249

250+
- If you have a repository with many untracked files, the git prompt can become very slow.
251+
You can disable the display of untracked files on a per repository basis by setting
252+
``GIT_PROMPT_SHOW_UNTRACKED_FILES=no`` in your ``.bash-git-rc`` in the repository or
253+
by disabling it globally in your ``.bashrc``
254+
250255
- You can get help on the git prompt with the function ``git_prompt_help``.
251256
Examples are available with ``git_prompt_examples``.
252257
A list of all available named colors is available with `git_prompt_color_samples`

gitprompt.sh

+16-2
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,18 @@ function setGitPrompt() {
332332
fi
333333

334334
unset GIT_PROMPT_IGNORE
335+
OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES}
336+
unset GIT_PROMPT_SHOW_UNTRACKED_FILES
335337

336338
if [[ -e "$repo/.bash-git-rc" ]]; then
337339
source "$repo/.bash-git-rc"
338340
fi
339341

342+
if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then
343+
GIT_PROMPT_SHOW_UNTRACKED_FILES=${OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES}
344+
fi
345+
unset OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES
346+
340347
if [[ "$GIT_PROMPT_IGNORE" = 1 ]]; then
341348
PS1="$EMPTY_PROMPT"
342349
return
@@ -433,6 +440,12 @@ function updatePrompt() {
433440
export __GIT_PROMPT_IGNORE_STASH=${GIT_PROMPT_IGNORE_STASH}
434441
export __GIT_PROMPT_SHOW_UPSTREAM=${GIT_PROMPT_SHOW_UPSTREAM}
435442

443+
if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then
444+
export __GIT_PROMPT_SHOW_UNTRACKED_FILES=all
445+
else
446+
export __GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES}
447+
fi
448+
436449
local -a git_status_fields
437450
git_status_fields=($("$__GIT_STATUS_CMD" 2>/dev/null))
438451

@@ -528,7 +541,8 @@ function gp_add_virtualenv_to_prompt {
528541
function is_function {
529542
declare -Ff "$1" >/dev/null;
530543
}
531-
#Helper function that truncates $PWD depending on window width
544+
545+
# Helper function that truncates $PWD depending on window width
532546
function gp_truncate_pwd {
533547
local tilde="~"
534548
local newPWD="${PWD/#${HOME}/${tilde}}"
@@ -537,7 +551,7 @@ function gp_truncate_pwd {
537551
echo -n "$newPWD"
538552
}
539553

540-
#Sets the window title to the given argument string
554+
# Sets the window title to the given argument string
541555
function gp_set_window_title {
542556
echo -ne "\033]0;"$@"\007"
543557
}

gitstatus.sh

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ if [ -z "${__GIT_PROMPT_DIR}" ]; then
1515
__GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
1616
fi
1717

18-
if [ -z "${GIT_SHOW_UNTRACKED_FILES}" ]; then
19-
GIT_SHOW_UNTRACKED_FILES="all"
20-
fi
21-
22-
gitstatus=$( LC_ALL=C git status --untracked-files=${GIT_SHOW_UNTRACKED_FILES} --porcelain --branch )
18+
gitstatus=$( LC_ALL=C git status --untracked-files=${__GIT_PROMPT_SHOW_UNTRACKED_FILES} --porcelain --branch )
2319

2420
# if the status is fatal, exit now
2521
[[ "$?" -ne 0 ]] && exit 0

0 commit comments

Comments
 (0)