From 38f7dbc0bb891719c2773714c170fe8fea035d95 Mon Sep 17 00:00:00 2001 From: hgmoll Date: Wed, 13 Jul 2016 15:12:43 +0200 Subject: [PATCH 1/6] Fix index lock issue --- gitprompt.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 992436f6..86c9d227 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -437,6 +437,20 @@ function replaceSymbols() { echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} } +function createPrivateIndex { + # Create a copy of the index to avoid conflicts with parallel git commands, e.g. git rebase. + local __GIT_INDEX_FILE + local __GIT_INDEX_PRIVATE + if [[ -z "$GIT_INDEX_FILE" ]]; then + __GIT_INDEX_FILE="$(git rev-parse --git-dir)/index" + else + __GIT_INDEX_FILE="$GIT_INDEX_FILE" + fi + __GIT_INDEX_PRIVATE="/tmp/git-index-private$$" + cp "$__GIT_INDEX_FILE" "$__GIT_INDEX_PRIVATE" 2>/dev/null + echo "$__GIT_INDEX_PRIVATE" +} + function updatePrompt() { local LAST_COMMAND_INDICATOR local PROMPT_LEADING_SPACE @@ -456,6 +470,11 @@ function updatePrompt() { export __GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES} fi + local GIT_INDEX_PRIVATE="$(createPrivateIndex)" + #important to define GIT_INDEX_FILE as local: This way it only affects this function (and below) - even with the export afterwards + local GIT_INDEX_FILE + export GIT_INDEX_FILE="$GIT_INDEX_PRIVATE" + local -a git_status_fields git_status_fields=($("$__GIT_STATUS_CMD" 2>/dev/null)) @@ -528,6 +547,7 @@ function updatePrompt() { fi PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}${ResetColor}}" + rm "$GIT_INDEX_PRIVATE" 2>/dev/null } # Helper function that returns virtual env information to be set in prompt From 1d32369dabb07c1875a24b0f0f571d63c3ba3f4b Mon Sep 17 00:00:00 2001 From: nexayq Date: Fri, 15 Jul 2016 15:44:26 +0200 Subject: [PATCH 2/6] Add git_prompt_toggle to disable/enable gitprompt --- README.md | 7 +++++++ gitprompt.sh | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ec3cd10..9a53be5d 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,13 @@ GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 fo git_prompt_reset ``` +- You can disable/enable gitprompt by runnning: + +```sh +$ git_prompt_toggle` +``` + + **Enjoy!** ## Alternative RPM Install diff --git a/gitprompt.sh b/gitprompt.sh index 992436f6..899bea44 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -331,7 +331,7 @@ function setGitPrompt() { git_prompt_config - if [[ ! -e "$repo" ]]; then + if [[ ! -e "$repo" ]] || [[ "$GIT_PROMPT_DISABLE" = 1 ]]; then PS1="$EMPTY_PROMPT" return fi @@ -570,6 +570,16 @@ function prompt_callback_default { return } +# toggle gitprompt +function git_prompt_toggle() { + if [[ "$GIT_PROMPT_DISABLE" = 1 ]]; then + GIT_PROMPT_DISABLE=0 + else + GIT_PROMPT_DISABLE=1 + fi + return +} + function gp_install_prompt { if [ -z "$OLD_GITPROMPT" ]; then OLD_GITPROMPT=$PS1 From e209406efacde47c1c223821e7f0d02db389a990 Mon Sep 17 00:00:00 2001 From: nexayq Date: Fri, 15 Jul 2016 15:47:19 +0200 Subject: [PATCH 3/6] Fixed typos in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a53be5d..c4bc2db1 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ git_prompt_reset - You can disable/enable gitprompt by runnning: ```sh -$ git_prompt_toggle` +git_prompt_toggle ``` From 66b4a94bdf35f658ca7256cd98420dca24a30d91 Mon Sep 17 00:00:00 2001 From: DrVanScott Date: Sun, 17 Jul 2016 16:57:17 +0200 Subject: [PATCH 4/6] rewrite bash 4 ;;& operator --- gitstatus.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index 8dcd49b6..e3059904 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -26,15 +26,18 @@ num_conflicts=0 num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} - case "$status" in - \#\#) branch_line="${line/\.\.\./^}" ;; - ?M) ((num_changed++)) ;;& - ?D) ((num_changed++)) ;;& - U?) ((num_conflicts++)) ;;& - \?\?) ((num_untracked++)) ;; - \ ?) ;; - *) ((num_staged++)) ;; - esac + while true + do + case "$status" in + \#\#) branch_line="${line/\.\.\./^}"; break ;; + ?M) ((num_changed++)); status=${status:0:1}"_" ;; + ?D) ((num_changed++)); status=${status:0:1}"_" ;; + U?) ((num_conflicts++)); break ;; + \?\?) ((num_untracked++)); break ;; + \ ?) break ;; + *) ((num_staged++)); break ;; + esac + done done <<< "$gitstatus" num_stashed=0 From 904b82bb5835e4257e178314affe9bddc28b8e0c Mon Sep 17 00:00:00 2001 From: DrVanScott Date: Sun, 17 Jul 2016 17:28:34 +0200 Subject: [PATCH 5/6] rewrite bash 4 ;;& operator (two step) --- gitstatus.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index e3059904..e2b6bce3 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -26,17 +26,26 @@ num_conflicts=0 num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} - while true + while [[ -n $status ]] do case "$status" in +#two fixed character matches, loop finished \#\#) branch_line="${line/\.\.\./^}"; break ;; - ?M) ((num_changed++)); status=${status:0:1}"_" ;; - ?D) ((num_changed++)); status=${status:0:1}"_" ;; - U?) ((num_conflicts++)); break ;; \?\?) ((num_untracked++)); break ;; - \ ?) break ;; - *) ((num_staged++)); break ;; + U?) ((num_conflicts++)); break;; + ?U) ((num_conflicts++)); break;; + DD) ((num_conflicts++)); break;; + AA) ((num_conflicts++)); break;; +#two character matches, first loop + ?M) ((num_changed++)) ;; + ?D) ((num_changed++)) ;; + ?\ ) ;; +#single character matches, second loop + U) ((num_conflicts++)) ;; + \ ) ;; + *) ((num_staged++)) ;; esac + status=${status:0:-1} done done <<< "$gitstatus" From 5130f3b07d14fe9ed3f8e7cf254fdc91dfdf4103 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 18 Jul 2016 10:49:29 +0200 Subject: [PATCH 6/6] Indentation same as other loop constructs --- gitstatus.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gitstatus.sh b/gitstatus.sh index e2b6bce3..6d7db3c1 100755 --- a/gitstatus.sh +++ b/gitstatus.sh @@ -26,21 +26,20 @@ num_conflicts=0 num_untracked=0 while IFS='' read -r line || [[ -n "$line" ]]; do status=${line:0:2} - while [[ -n $status ]] - do + while [[ -n $status ]]; do case "$status" in -#two fixed character matches, loop finished + #two fixed character matches, loop finished \#\#) branch_line="${line/\.\.\./^}"; break ;; \?\?) ((num_untracked++)); break ;; U?) ((num_conflicts++)); break;; ?U) ((num_conflicts++)); break;; DD) ((num_conflicts++)); break;; AA) ((num_conflicts++)); break;; -#two character matches, first loop + #two character matches, first loop ?M) ((num_changed++)) ;; ?D) ((num_changed++)) ;; ?\ ) ;; -#single character matches, second loop + #single character matches, second loop U) ((num_conflicts++)) ;; \ ) ;; *) ((num_staged++)) ;;