mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-12 21:39:48 +01:00
git: better algorithm to decide what's the main branch
Fixes #9103 Co-authored-by: Yufan You <ouuansteve@gmail.com>
This commit is contained in:
parent
9cdc276496
commit
55a98fc06d
1 changed files with 22 additions and 5 deletions
|
@ -25,13 +25,30 @@ function work_in_progress() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if main exists and use instead of master
|
# Get the default 'main' branch
|
||||||
|
# Marc(2020-07-11): I hope to be able to remove this someday
|
||||||
function git_main_branch() {
|
function git_main_branch() {
|
||||||
if [[ -n "$(git branch --list master)" ]]; then
|
# Get default branch from the origin remote
|
||||||
echo master
|
local branch
|
||||||
else
|
branch="${$(command git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null)#refs/remotes/origin/}"
|
||||||
echo main
|
|
||||||
|
if [[ -n "$branch" ]]; then
|
||||||
|
echo "$branch"
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Look up list of local branches and return the first one that exists
|
||||||
|
local -a branches
|
||||||
|
branches=(${(@f)"$(command git for-each-ref --format='%(refname:short)' refs/heads 2>/dev/null)"})
|
||||||
|
for branch in master main; do
|
||||||
|
if (( ${branches[(Ie)$branch]} )); then
|
||||||
|
echo "$branch"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo master
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue