浏览代码

fix(lib): don't return clean with `hide-dirty=1` in `parse_git_dirty` (#10897)

Will LE 2 年之前
父节点
当前提交
4674384d1a
共有 1 个文件被更改,包括 20 次插入16 次删除
  1. 20 16
      lib/git.zsh

+ 20 - 16
lib/git.zsh

@@ -34,26 +34,30 @@ function git_prompt_info() {
 
 # Checks if working tree is dirty
 function parse_git_dirty() {
+  if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" == "1" ]]; then
+    return 0
+  fi
+
   local STATUS
   local -a FLAGS
   FLAGS=('--porcelain')
-  if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
-    if [[ "${DISABLE_UNTRACKED_FILES_DIRTY:-}" == "true" ]]; then
-      FLAGS+='--untracked-files=no'
-    fi
-    case "${GIT_STATUS_IGNORE_SUBMODULES:-}" in
-      git)
-        # let git decide (this respects per-repo config in .gitmodules)
-        ;;
-      *)
-        # if unset: ignore dirty submodules
-        # other values are passed to --ignore-submodules
-        FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
-        ;;
-    esac
-    STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
+  if [[ "${DISABLE_UNTRACKED_FILES_DIRTY:-}" == "true" ]]; then
+    FLAGS+='--untracked-files=no'
   fi
-  if [[ -n $STATUS ]]; then
+
+  case "${GIT_STATUS_IGNORE_SUBMODULES:-}" in
+    git)
+      # let git decide (this respects per-repo config in .gitmodules)
+      ;;
+    *)
+      # if unset: ignore dirty submodules
+      # other values are passed to --ignore-submodules
+      FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
+      ;;
+  esac
+
+  STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
+  if [[ -n "$STATUS" ]]; then
     echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
   else
     echo "$ZSH_THEME_GIT_PROMPT_CLEAN"