From 0c5eae7e44531c1a191def9e95ab991be7799e64 Mon Sep 17 00:00:00 2001 From: ElisarEisenbach Date: Sun, 10 Aug 2025 16:33:11 +0300 Subject: [PATCH] refactor(git): streamline default branch detection in git_main_branch function Updated the `git_main_branch` function to utilize `git rev-parse` for retrieving the default branch from remote HEAD references. This change simplifies the logic by directly checking if the reference starts with the remote name, enhancing clarity and reliability in branch detection. --- plugins/git/git.plugin.zsh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 4bfabcf29..9897b0f7c 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -46,10 +46,9 @@ function git_main_branch() { # Fallback: try to get the default branch from remote HEAD symbolic refs for remote in origin upstream; do - ref=$(command git symbolic-ref --quiet refs/remotes/$remote/HEAD 2>/dev/null) - if [[ -n $ref ]]; then - echo ${ref#refs/remotes/$remote/} - return 0 + ref=$(command git rev-parse --abbrev-ref $remote/HEAD 2>/dev/null) + if [[ $ref == $remote/* ]]; then + echo ${ref#"$remote/"}; return 0 fi done