1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2026-02-12 12:21:00 +01:00

2 Commits

Author SHA1 Message Date
ElisarEisenbach
2525dae661 feat(git): use remote default branch to guess main branch (#13212)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
2025-08-26 11:13:21 +08:00
Dennis Dashkevich
266bc17ab3 fix(chruby): avoid adding PATH entries twice (#12980) 2025-08-26 10:51:00 +08:00
2 changed files with 25 additions and 21 deletions

View File

@@ -15,6 +15,13 @@ _source-from-omz-settings() {
fi fi
} }
_source-from-default-location() {
[[ -r /usr/local/share/chruby/chruby.sh ]] || return 1
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
}
_source-from-homebrew() { _source-from-homebrew() {
(( $+commands[brew] )) || return 1 (( $+commands[brew] )) || return 1
@@ -36,27 +43,14 @@ _source-from-homebrew() {
source $_brew_prefix/share/chruby/auto.sh source $_brew_prefix/share/chruby/auto.sh
} }
_load-chruby-dirs() {
local dir
for dir in "$HOME/.rubies" "$PREFIX/opt/rubies"; do
if [[ -d "$dir" ]]; then
RUBIES+=("$dir")
fi
done
}
# Load chruby # Load chruby
if _source-from-omz-settings; then _source-from-omz-settings || \
_load-chruby-dirs _source-from-default-location || \
elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then _source-from-homebrew
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
_load-chruby-dirs
elif _source-from-homebrew; then
_load-chruby-dirs
fi
unfunction _source-from-homebrew _source-from-omz-settings _load-chruby-dirs unfunction _source-from-homebrew \
_source-from-default-location \
_source-from-omz-settings
## chruby utility functions and aliases ## chruby utility functions and aliases

View File

@@ -31,10 +31,12 @@ function git_develop_branch() {
return 1 return 1
} }
# Check if main exists and use instead of master # Get the default branch name from common branch names or fallback to remote HEAD
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 remote ref
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,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}
@@ -42,6 +44,14 @@ function git_main_branch() {
fi fi
done done
# Fallback: try to get the default branch from remote HEAD symbolic refs
for remote in origin upstream; do
ref=$(command git rev-parse --abbrev-ref $remote/HEAD 2>/dev/null)
if [[ $ref == $remote/* ]]; then
echo ${ref#"$remote/"}; return 0
fi
done
# If no main branch was found, fall back to master but return error # If no main branch was found, fall back to master but return error
echo master echo master
return 1 return 1