0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00

fix(git): fix fallback to develop branch if master not found (#11966)

This commit is contained in:
Marc Cornellà 2023-10-14 16:40:45 +02:00 committed by GitHub
parent f7130bb529
commit f939768751
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,26 +20,31 @@ function current_branch() {
function git_develop_branch() {
command git rev-parse --git-dir &>/dev/null || return
local branch
for branch in dev devel development; do
for branch in dev devel develop development; do
if command git show-ref -q --verify refs/heads/$branch; then
echo $branch
return
return 0
fi
done
echo develop
return 1
}
# Check if main exists and use instead of master
function 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}; do
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}; do
if command git show-ref -q --verify $ref; then
echo ${ref:t}
return
return 0
fi
done
# If no main branch was found, fall back to master but return error
echo master
return 1
}
function grename() {
@ -129,6 +134,8 @@ function gbda() {
git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null
local default_branch=$(git_main_branch)
(( ! $? )) || default_branch=$(git_develop_branch)
git for-each-ref refs/heads/ "--format=%(refname:short)" | \
while read branch; do
local merge_base=$(git merge-base $default_branch $branch)