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.
This commit is contained in:
ElisarEisenbach 2025-08-10 16:33:11 +03:00
commit 0c5eae7e44

View file

@ -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