mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-27 15:30:15 +08:00
fix(git): fix fallback to develop branch if master
not found (#11966)
This commit is contained in:
parent
f7130bb529
commit
f939768751
@ -20,26 +20,31 @@ function current_branch() {
|
|||||||
function git_develop_branch() {
|
function git_develop_branch() {
|
||||||
command git rev-parse --git-dir &>/dev/null || return
|
command git rev-parse --git-dir &>/dev/null || return
|
||||||
local branch
|
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
|
if command git show-ref -q --verify refs/heads/$branch; then
|
||||||
echo $branch
|
echo $branch
|
||||||
return
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo develop
|
echo develop
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if main exists and use instead of master
|
# Check if main exists and use instead of master
|
||||||
function git_main_branch() {
|
function git_main_branch() {
|
||||||
command git rev-parse --git-dir &>/dev/null || return
|
command git rev-parse --git-dir &>/dev/null || return
|
||||||
local ref
|
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
|
if command git show-ref -q --verify $ref; then
|
||||||
echo ${ref:t}
|
echo ${ref:t}
|
||||||
return
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# If no main branch was found, fall back to master but return error
|
||||||
echo master
|
echo master
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function grename() {
|
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
|
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)
|
local default_branch=$(git_main_branch)
|
||||||
|
(( ! $? )) || default_branch=$(git_develop_branch)
|
||||||
|
|
||||||
git for-each-ref refs/heads/ "--format=%(refname:short)" | \
|
git for-each-ref refs/heads/ "--format=%(refname:short)" | \
|
||||||
while read branch; do
|
while read branch; do
|
||||||
local merge_base=$(git merge-base $default_branch $branch)
|
local merge_base=$(git merge-base $default_branch $branch)
|
||||||
|
Loading…
Reference in New Issue
Block a user