mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 02:35:38 +01:00
Update git.plugin.zsh
refactor: use symbolic-ref to determine default branch Replaced manual scanning of possible main branch names with `git symbolic-ref refs/remotes/origin/HEAD` for a more reliable and modern approach to detecting the repository's default branch. Includes fallback to traditional branch name checks if the symbolic-ref fails, ensuring backward compatibility.
This commit is contained in:
parent
042605ee6b
commit
65dbf9e267
1 changed files with 14 additions and 8 deletions
|
|
@ -31,19 +31,25 @@ function git_develop_branch() {
|
|||
return 1
|
||||
}
|
||||
|
||||
# Check if main exists and use instead of master
|
||||
function git_main_branch() {
|
||||
unction git_main_branch() {
|
||||
command git rev-parse --git-dir &>/dev/null || return
|
||||
|
||||
local ref
|
||||
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do
|
||||
if command git show-ref -q --verify $ref; then
|
||||
echo ${ref:t}
|
||||
return 0
|
||||
ref=$(git symbolic-ref --quiet refs/remotes/origin/HEAD 2>/dev/null)
|
||||
if [[ $? -eq 0 && -n "$ref" ]]; then
|
||||
echo "${ref##*/}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Fallback if origin/HEAD is not set
|
||||
for branch in main master trunk default stable; do
|
||||
if git show-ref -q --verify "refs/heads/$branch"; then
|
||||
echo "$branch"
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
# If no main branch was found, fall back to master but return error
|
||||
echo master
|
||||
echo "master" # Default fallback
|
||||
return 1
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue