e2f2489a666caf238804783b4e8851a781ac6ffc

Author
Joseph Heyburn <34041368+jdheyburn@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(git): silently fail in `git_main_branch` if not in a git repo (#9484)

Co-authored-by: Marc Cornellà <marc.cornella@live.com>

Diff

 1diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
 2index bf26199768f3fc9015b51ac10e53f5f2cbdf0f87..e32136f15ac14882a10d1a55229093680687ca9c 100644
 3--- a/plugins/git/git.plugin.zsh
 4+++ b/plugins/git/git.plugin.zsh
 5@@ -31,6 +31,7 @@ function work_in_progress() {
 6 
 7 # Check if main exists and use instead of master
 8 function git_main_branch() {
 9+  command git rev-parse --git-dir &>/dev/null || return
10   local branch
11   for branch in main trunk; do
12     if command git show-ref -q --verify refs/heads/$branch; then