Skip to content

Commit 63f9ec5

Browse files
committed
Fix nested directory git status properly
1 parent 4f7058b commit 63f9ec5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

k.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,20 +391,21 @@ k () {
391391
# then mark appropriately
392392
if (( INSIDE_WORK_TREE == 0 )); then
393393
if (( IS_DIRECTORY )); then
394-
if command git --git-dir="$GIT_TOPLEVEL/.git" --work-tree="${NAME}" diff --quiet --ignore-submodules HEAD &>/dev/null # if dirty
394+
if command git --git-dir="$GIT_TOPLEVEL/.git" --work-tree="${NAME}" diff --stat --quiet --ignore-submodules HEAD &>/dev/null # if dirty
395395
then REPOMARKER=$'\e[38;5;46m|\e[0m' # Show a green vertical bar for clean
396396
else REPOMARKER=$'\e[0;31m+\e[0m' # Show a red vertical bar if dirty
397397
fi
398398
fi
399399
else
400400
if (( IS_DIRECTORY )); then
401-
# If the directory is ignored, skip it
402-
if command git check-ignore --quiet ${NAME} 2>/dev/null
403-
then STATUS='!!'
404-
else STATUS=$(command git --git-dir=$GIT_TOPLEVEL/.git --work-tree=$GIT_TOPLEVEL status --porcelain --untracked-files=normal ${${${NAME:a}##$GIT_TOPLEVEL}#*/})
401+
# If the directory isn't ignored or clean, we'll just say it's dirty
402+
if command git check-ignore --quiet ${NAME} 2>/dev/null; then STATUS='!!'
403+
elif command git diff --stat --quiet --ignore-submodules ${NAME} 2> /dev/null; then STATUS='';
404+
else STATUS=' M'
405405
fi
406406
else
407-
STATUS=$(command git status --porcelain --ignored --untracked-files=normal $NAME)
407+
# File
408+
STATUS=$(command git status --porcelain --ignored --untracked-files=normal $GIT_TOPLEVEL/${${${NAME:a}##$GIT_TOPLEVEL}#*/})
408409
fi
409410
STATUS=${STATUS[1,2]}
410411
if [[ $STATUS == ' M' ]]; then REPOMARKER=$'\e[0;31m+\e[0m'; # Tracked & Dirty

0 commit comments

Comments
 (0)