Skip to content

Commit 3463426

Browse files
committed
fix(self-update): respect option flags
Signed-off-by: Vladislav Doster <[email protected]>
1 parent d65206f commit 3463426

File tree

4 files changed

+53
-56
lines changed

4 files changed

+53
-56
lines changed

_zinit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ _zinit_run(){
270270
} # ]]]
271271
# FUNCTION: _zinit_self_update [[[
272272
_zinit_self_update(){
273+
_arguments \
274+
'(-h --help)'{-h,--help}'[Show this help message]' \
275+
'(-n --no-pager)'{-n,--no-pager}'[Do not pipe Git output into a pager]' \
276+
'(-q --quiet)'{-q,--quiet}'[Quiet, suppress feedback messages]' \
277+
&& ret=0
273278
} # ]]]
274279
# FUNCTION: _zinit_snippet [[[
275280
_zinit_snippet(){

tests/commands.zunit

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@
5959
assert $state equals 1
6060
}
6161
@test 'self-update' {
62-
run zinit self-update
63-
assert $output contains 'Already up-to-date.'
64-
assert $state equals 0
62+
run zinit self-update --quiet; assert $state equals 0
63+
assert $output contains 'Updated Zinit'
64+
65+
run zinit self-update; assert $state equals 0
66+
assert $output contains 'Updating Zinit';assert $output contains 'Updated Zinit'
6567
}
6668
@test 'set-debug' {
6769
ZINIT+=(DEBUG 'true')

zinit-autoload.zsh

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,62 +1833,52 @@ print -- "\nAvailable ice-modifiers:\n\n${ice_order[*]}"
18331833
} # ]]]
18341834
# FUNCTION: .zinit-self-update [[[
18351835
# Updates Zinit code (does a git pull)
1836-
.zinit-self-update() {
1836+
.zinit-self-update () {
18371837
builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
18381838
setopt extendedglob typesetsilent warncreateglobal
1839-
1840-
if .zi-check-for-git-changes "$ZINIT[BIN_DIR]"; then
1841-
[[ $1 = -q ]] && +zi-log "{pre}[self-update]{info} updating zinit repository{msg2}" \
1842-
1843-
local nl=$'\n' escape=$'\x1b['
1844-
local current_branch=$(git -C $ZINIT[BIN_DIR] rev-parse --abbrev-ref HEAD)
1845-
# local current_branch='main'
1846-
local -a lines
1847-
(
1848-
builtin cd -q "$ZINIT[BIN_DIR]" \
1849-
&& +zi-log -n "{pre}[self-update]{info} fetching latest changes from {obj}$current_branch{info} branch$nl{rst}" \
1850-
&& command git fetch --quiet \
1851-
&& lines=( ${(f)"$(command git log --color --date=short --pretty=format:'%Cgreen%cd %h %Creset%s %Cred%d%Creset || %b' ..origin/HEAD)"} )
1852-
if (( ${#lines} > 0 )); then
1853-
# Remove the (origin/main ...) segments, to expect only tags to appear
1854-
lines=( "${(S)lines[@]//\(([,[:blank:]]#(origin|HEAD|master|main)[^a-zA-Z]##(HEAD|origin|master|main)[,[:blank:]]#)#\)/}" )
1855-
# Remove " ||" if it ends the line (i.e. no additional text from the body)
1856-
lines=( "${lines[@]/ \|\|[[:blank:]]#(#e)/}" )
1857-
# If there's no ref-name, 2 consecutive spaces occur - fix this
1858-
lines=( "${lines[@]/(#b)[[:space:]]#\|\|[[:space:]]#(*)(#e)/|| ${match[1]}}" )
1859-
lines=( "${lines[@]/(#b)$escape([0-9]##)m[[:space:]]##${escape}m/$escape${match[1]}m${escape}m}" )
1860-
# Replace what follows "|| ..." with the same thing but with no
1861-
# newlines, and also only first 10 words (the (w)-flag enables
1862-
# word-indexing)
1863-
lines=( "${lines[@]/(#b)[[:blank:]]#\|\|(*)(#e)/| ${${match[1]//$nl/ }[(w)1,(w)10]}}" )
1839+
(( !OPTS[opt_-q,--quiet] )) && +zi-log "{m} {b}Updating Zinit...{rst}"
1840+
local nl=$'\n' escape=$'\x1b['
1841+
local -a lines
1842+
(
1843+
builtin cd -q "$ZINIT[BIN_DIR]" && {
1844+
(( !OPTS[opt_-q,--quiet] )) && +zi-log -n "{m} {b}self-update{rst}: fetching latest changes from {obj}main{rst} branch{nl}{rst}"
1845+
} && command git fetch --all --quiet && lines=(${(f)"$(command git --no-pager log --color --date=short --pretty='format:%C(yellow)%h%C(auto,magenta)% %C(auto,blue)%>(12,trunc)%ad %C(auto,reset)%s%C(auto,red)% gD% D %C(auto,green)%aN' -- ..origin/main)"})
1846+
if (( ${#lines} > 0 )); then
1847+
lines=("${(S)lines[@]//\(([,[:blank:]]#(origin|HEAD|master|main)[^a-zA-Z]##(HEAD|origin|master|main)[,[:blank:]]#)#\)/}")
1848+
lines=("${lines[@]/ \|\|[[:blank:]]#(#e)/}")
1849+
lines=("${lines[@]/(#b)[[:space:]]#\|\|[[:space:]]#(*)(#e)/|| ${match[1]}}")
1850+
lines=("${lines[@]/(#b)$escape([0-9]##)m[[:space:]]##${escape}m/$escape${match[1]}m${escape}m}")
1851+
lines=("${lines[@]/(#b)[[:blank:]]#\|\|(*)(#e)/| ${${match[1]//$nl/ }[(w)1,(w)10]}}")
1852+
(( !OPTS[opt_-q,--quiet] )) && {
18641853
builtin print -rl -- "${lines[@]}" | .zinit-pager
18651854
builtin print
1866-
fi
1867-
if [[ $1 != -q ]] {
1868-
command git pull --no-stat --ff-only origin main
1869-
} else {
1870-
command git pull --no-stat --quiet --ff-only origin main
18711855
}
1872-
)
1873-
if [[ $1 != -q ]] {
1874-
+zi-log "{pre}[self-update]{info} compiling zinit via {obj}zcompile{rst}"
1875-
}
1876-
command rm -f $ZINIT[BIN_DIR]/*.zwc(DN)
1877-
zcompile -U $ZINIT[BIN_DIR]/zinit.zsh
1878-
zcompile -U $ZINIT[BIN_DIR]/zinit-{'side','install','autoload','additional'}.zsh
1879-
zcompile -U $ZINIT[BIN_DIR]/share/git-process-output.zsh
1880-
# Load for the current session
1881-
[[ $1 != -q ]] && +zi-log "{pre}[self-update]{info} reloading zinit for the current session{rst}"
1882-
1883-
# +zi-log "{pre}[self-update]{info} resetting zinit repository via{rst}: {cmd}${ICE[reset]:-git reset --hard HEAD}{rst}"
1884-
source $ZINIT[BIN_DIR]/zinit.zsh
1885-
zcompile -U $ZINIT[BIN_DIR]/zinit-{'side','install','autoload'}.zsh
1886-
# Read and remember the new modification timestamps
1887-
local file
1888-
for file ( "" -side -install -autoload ) {
1889-
.zinit-get-mtime-into "${ZINIT[BIN_DIR]}/zinit$file.zsh" "ZINIT[mtime$file]"
1890-
}
1891-
fi
1856+
fi
1857+
local branch='origin main'
1858+
if (( !OPTS[opt_-q,--quiet] )); then
1859+
command git pull --autostash --ff-only --no-stat --squash ${=branch}
1860+
else
1861+
command git pull --autostash --ff-only --no-stat --quiet --squash ${=branch}
1862+
fi
1863+
# (( $? )) && {
1864+
# +zi-log "{w} Unable to update Zinit"
1865+
# return 0
1866+
# }
1867+
)
1868+
(( $? )) && {
1869+
+zi-log "{w} Unable to update Zinit"
1870+
return 0
1871+
}
1872+
command rm -f ${ZINIT[BIN_DIR]}/*.zwc(DN)
1873+
(( !OPTS[opt_-q,--quiet] )) && +zi-log "{m} {b}self-update{rst}: compiling zinit via {obj}zcompile{rst}"
1874+
local file
1875+
for file in ${ZINIT[BIN_DIR]}/zinit(*).zsh(.N); do
1876+
builtin zcompile -Uz ${file:A}
1877+
.zinit-get-mtime-into "${f:A}" "ZINIT[mtime${file:t}]"
1878+
done
1879+
(( !OPTS[opt_-q,--quiet] )) && +zi-log "{m} {b}self-update{rst}: reloading zinit for the current session{rst}"
1880+
builtin source ${ZINIT[BIN_DIR]}/zinit.zsh
1881+
+zi-log "{i} {b}Updated Zinit{rst}"
18921882
} # ]]]
18931883

18941884
# FUNCTION: .zinit-show-all-reports [[[

zinit.zsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,7 @@ zinit() {
26052605
delete "--all|--clean|--help|--quiet|--yes|-a|-c|-h|-q|-y"
26062606
env-whitelist "--help|--verbose|-h|-v"
26072607
light "--help|-b|-h"
2608+
self-update "--help|--no-pager|--quiet|-h|-n|-q"
26082609
snippet "--command|--force|--help|-f|-h|-x"
26092610
times "--help|-h|-m|-s"
26102611
unload "--help|--quiet|-h|-q"
@@ -2613,8 +2614,7 @@ zinit() {
26132614
)
26142615

26152616
cmd="$1"
2616-
if [[ $cmd == (times|unload|env-whitelist|update|snippet|load|light|cdreplay|\
2617-
cdclear) ]]; then
2617+
if [[ $cmd == (cdclear|cdreplay|env-whitelist|light|load|self-update|snippet|times|unload|update) ]]; then
26182618
if (( $@[(I)-*] || OPTS[opt_-h,--help] )); then
26192619
.zinit-parse-opts "$cmd" "$@"
26202620
if (( OPTS[opt_-h,--help] )); then

0 commit comments

Comments
 (0)