This question is based on the thread.
I have the following Git-prompt at the moment.
I get the following warning after cd
ing to a non-Git folder.
fatal: Not a git repository (or any of the parent directories): .git
fatal: git diff [--no-index] takes two paths
fatal: Not a git repository (or any of the parent directories): .git
fatal: git diff [--no-index] takes two paths
My current code for Git-prompt in Zsh
# get the name of the branch we are on
git_prompt_info() {
ref=$(git symbolic-ref HEAD | cut -d'/' -f3)
echo $ref
}
get_git_dirty() {
git diff --quiet || echo '*'
}
autoload -U colors
colors
setopt prompt_subst
PROMPT='%{$fg[blue]%}%c %{$fg_bold[red]%}$(git_prompt_info)$(get_git_dirty)%{$fg[blue]%} $ %{$reset_color%}'
The problem is the following code which causes the warning for non-Git folders
get_git_dirty() {
git diff --quiet || echo '*'
}
I tried to solve the bug by redirecting errors to /tmp/ unsuccessfully such that
get_git_dirty() {
git diff --quiet 2>/tmp/error || echo '*' 2>/tmp/error
}
How can you get rid of the warning messages for non-git directories?