Skip to content

Commit 23c47e1

Browse files
committed
bugfix: zinit self-update respects the current branch
Fix bug in Zinit `self-update` command that used the `main` branch instead of using current branch. Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
1 parent 3a7dc95 commit 23c47e1

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

doc/zsdoc/zinit-autoload.zsh.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ ____
10681068
User-action entry point.
10691069
____
10701070
1071-
Has 45 line(s). Calls functions:
1071+
Has 42 line(s). Calls functions:
10721072
10731073
.zinit-self-update
10741074
|-- zinit.zsh/+zinit-message

zinit-autoload.zsh

+11-13
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,13 @@ ZINIT[EXTENDED_GLOB]=""
714714
[[ $1 = -q ]] && +zinit-message "{info2}Updating Zinit{…}{rst}"
715715

716716
local nl=$'\n' escape=$'\x1b['
717+
local current_branch=$(builtin pushd $ZINIT[BIN_DIR] > /dev/null && git branch --show-current && popd > /dev/null)
717718
local -a lines
718-
( builtin cd -q "$ZINIT[BIN_DIR]" && \
719-
command git checkout main &>/dev/null && \
720-
command git fetch --quiet && \
721-
lines=( ${(f)"$(command git --no-pager log --color --date=short --pretty=format:'%Cgreen%cd %h %Creset%s %Cred%d%Creset || %b' ..FETCH_HEAD)"} )
719+
(
720+
builtin cd -q "$ZINIT[BIN_DIR]" \
721+
&& +zinit-message -n "{pre}[self-update]{msg2} fetching changes for {msg2}$current_branch$nl{cmd}" \
722+
&& command git fetch --quiet \
723+
&& lines=( ${(f)"$(command git log --color --date=short --pretty=format:'%Cgreen%cd %h %Creset%s %Cred%d%Creset || %b' ..FETCH_HEAD)"} )
722724
if (( ${#lines} > 0 )); then
723725
# Remove the (origin/main ...) segments, to expect only tags to appear
724726
lines=( "${(S)lines[@]//\(([,[:blank:]]#(origin|HEAD|master|main)[^a-zA-Z]##(HEAD|origin|master|main)[,[:blank:]]#)#\)/}" )
@@ -727,8 +729,9 @@ ZINIT[EXTENDED_GLOB]=""
727729
# If there's no ref-name, 2 consecutive spaces occur - fix this
728730
lines=( "${lines[@]/(#b)[[:space:]]#\|\|[[:space:]]#(*)(#e)/|| ${match[1]}}" )
729731
lines=( "${lines[@]/(#b)$escape([0-9]##)m[[:space:]]##${escape}m/$escape${match[1]}m${escape}m}" )
730-
# Replace what follows "|| ..." with the same thing but with no newlines,
731-
# and also only first 10 words (the (w)-flag enables word-indexing)
732+
# Replace what follows "|| ..." with the same thing but with no
733+
# newlines, and also only first 10 words (the (w)-flag enables
734+
# word-indexing)
732735
lines=( "${lines[@]/(#b)[[:blank:]]#\|\|(*)(#e)/| ${${match[1]//$nl/ }[(w)1,(w)10]}}" )
733736
builtin print -rl -- "${lines[@]}" | .zinit-pager
734737
builtin print
@@ -744,17 +747,12 @@ ZINIT[EXTENDED_GLOB]=""
744747
}
745748
command rm -f $ZINIT[BIN_DIR]/*.zwc(DN)
746749
zcompile -U $ZINIT[BIN_DIR]/zinit.zsh
747-
zcompile -U $ZINIT[BIN_DIR]/zinit-side.zsh
748-
zcompile -U $ZINIT[BIN_DIR]/zinit-install.zsh
749-
zcompile -U $ZINIT[BIN_DIR]/zinit-autoload.zsh
750-
zcompile -U $ZINIT[BIN_DIR]/zinit-additional.zsh
750+
zcompile -U $ZINIT[BIN_DIR]/zinit-{'side','install','autoload','additional'}.zsh
751751
zcompile -U $ZINIT[BIN_DIR]/share/git-process-output.zsh
752752
# Load for the current session
753753
[[ $1 != -q ]] && +zinit-message "Reloading Zinit for the current session{…}"
754754
source $ZINIT[BIN_DIR]/zinit.zsh
755-
source $ZINIT[BIN_DIR]/zinit-side.zsh
756-
source $ZINIT[BIN_DIR]/zinit-install.zsh
757-
source $ZINIT[BIN_DIR]/zinit-autoload.zsh
755+
zcompile -U $ZINIT[BIN_DIR]/zinit-{'side','install','autoload'}.zsh
758756
# Read and remember the new modification timestamps
759757
local file
760758
for file ( "" -side -install -autoload ) {

0 commit comments

Comments
 (0)