mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 02:35:38 +01:00
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:
parent
86977d2bdf
commit
0c5eae7e44
1 changed files with 3 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue