This question is thread based .
I currently have the following Git -prompt. After cding to a non-git folder, the following warning appears.
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
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 that triggers a warning for Git folders
get_git_dirty() {
git diff --quiet || echo '*'
}
I tried to solve the problem by redirecting errors to / tmp / unsuccessfully, so that
get_git_dirty() {
git diff --quiet 2>/tmp/error || echo '*' 2>/tmp/error
}
How can you get rid of warning messages for non Git directories?
source
share