zsh shell, I am dynamically changing prompt depending on whether I am inside
git repository or not. I am using following git command to check:
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then ...
now I also want to distinguish whether current directory is being ignored by
git. So I have added one more check to my
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1) && ! $(git check-ignore . >/dev/null 2>&1); then ...
This works fine, but I was wondering whether I could simplify this into one
git command. Since the prompt is refreshed on every ENTER, it tends to slow down the shell noticeably on some slower machines.
The accepted solution from @Stephen Kitt works great, except in following situation:
I am using repository across filesystems. Lets say git resides at
/.git (because I want to track my config files in
/etc), but I also want to track some files in
/var/foo, which is a different partition/filesystem.
When I am located at
/ and execute following command, everything works as expected, and I get return code
/var/foo is being tracked):
# git check-ignore -q /var/foo
But when I am located anywhere in
/var, the same command fails with error code
128 and following error message:
# git check-ignore -q /var/foo fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
But I think this is only problem with the
check-ignore command. Otherwise git seems to work fine across filesystem. I can track files in
The expected behavior should be that
git check-ignore -q /var/foo returns
git check-ignore -q /var/bar returns
0, if it is not being tracked.
how can I fix this problem?