1c07001896de18cd0a742d7892b948ba7bab10c7

Author
David Sutherland <djsutho@gmail.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix(mercurial): correctly check for untracked files in `hg_dirty` (#2177)

Closes #2177
Closes #6197

Co-authored-by: Henrik Ravn <hravnx@gmail.com>

Diff

 1diff --git a/plugins/mercurial/mercurial.plugin.zsh b/plugins/mercurial/mercurial.plugin.zsh
 2index 6e72f0b1ee8d84ba89457d5139c89257ed09047b..9b85d02f6de29b91ba61b6e87a57b99c0ec097e5 100644
 3--- a/plugins/mercurial/mercurial.plugin.zsh
 4+++ b/plugins/mercurial/mercurial.plugin.zsh
 5@@ -91,13 +91,25 @@ function hg_prompt_info {
 6 }
 7 
 8 function hg_dirty {
 9-  local hg_status
10-  if ! hg_status="$(hg status -mar 2>/dev/null)"; then
11+  # Do nothing if clean / dirty settings aren't defined
12+  if [[ -z "$ZSH_THEME_HG_PROMPT_DIRTY" && -z "$ZSH_THEME_HG_PROMPT_CLEAN" ]]; then
13     return
14   fi
15 
16+  # Check if there are modifications
17+  local hg_status
18+  if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" = true ]]; then
19+    if ! hg_status="$(hg status -q 2>/dev/null)"; then
20+      return
21+    fi
22+  else
23+    if ! hg_status="$(hg status 2>/dev/null)"; then
24+      return
25+    fi
26+  fi
27+
28   # grep exits with 0 when dirty
29-  if command grep -Eq '^\s*[ACDIM!?L]' <<< "$hg_status"; then
30+  if command grep -Eq '^\s*[ACDIMR!?L].*$' <<< "$hg_status"; then
31     echo $ZSH_THEME_HG_PROMPT_DIRTY
32     return
33   fi