From 3567694a0f8f191cc50955151da0e38fd4f50711 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 2 Jan 2021 19:09:52 -0500 Subject: [PATCH] Use repository's default branch instead of hardcoding the default to `master`, when no branch is specified in `zmodule`. Fixes #422 --- CHANGELOG.md | 1 + README.md | 2 +- src/stage2/30_zmodule.zsh.erb | 6 +++--- src/stage2/80_zimfw.zsh.erb | 2 +- src/tools/install.zsh.erb | 4 ++-- src/tools/update.zsh.erb | 4 ++-- zimfw.zsh | 18 +++++++++--------- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4224243..37844fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Show error when no parameter is provided to `-c|--cmd`. +- Use repository's default branch instead of hardcoding the default to `master`. ## [1.3.2] - 2020-08-01 diff --git a/README.md b/README.md index 41bdbbd..28cccd9 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ initialized in the same order they are defined. Repository options: -b|--branch <branch_name> Use specified branch when installing and updating the module. - Overrides the tag option. Default: master. + Overrides the tag option. Default: the repository's default branch. -t|--tag <tag_name> Use specified tag when installing and updating the module. Overrides the branch option. -z|--frozen Don't install or update the module. diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index acff52e..db231f3 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -10,7 +10,7 @@ The modules are initialized in the same order they are defined. Repository options: %B-b%b|%B--branch%b Use specified branch when installing and updating the module. - Overrides the tag option. Default: %Bmaster%b. + Overrides the tag option. Default: the repository's default branch. %B-t%b|%B--tag%b Use specified tag when installing and updating the module. Overrides the branch option. %B-z%b|%B--frozen%b Don't install or update the module. @@ -39,7 +39,7 @@ Initialization options: fi setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB local zmodule=${1:t} zurl=${1} - local ztype=branch zrev=master + local ztype=branch zrev local -i zdisabled=0 zfrozen=0 local -a zfpaths zfunctions zcmds local zarg zdir @@ -121,7 +121,7 @@ Initialization options: done if (( _zprepare_zargs )); then if (( ! zfrozen )); then - _zmodules_zargs+=(${zmodule} ${zdir} ${zurl} ${ztype} ${zrev} ${_zprintlevel}) + _zmodules_zargs+=(${zmodule} ${zdir} ${zurl} ${ztype} "${zrev}" ${_zprintlevel}) fi else if (( zdisabled )); then diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 402ffb5..6147577 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -66,7 +66,7 @@ Options: install|update) _zimfw_source_zimrc 1 || return 1 autoload -Uz zargs && \ - zargs -n 9 -P 10 -- ${_zmodules_zargs} -- zsh -c ${ztool} ${1} && \ + zargs -n 9 -P 10 -- "${_zmodules_zargs[@]}" -- zsh -c ${ztool} ${1} && \ _zimfw_print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." || return 1 (( _zprintlevel-- )) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile diff --git a/src/tools/install.zsh.erb b/src/tools/install.zsh.erb index 34c4bea..2b876fa 100644 --- a/src/tools/install.zsh.erb +++ b/src/tools/install.zsh.erb @@ -2,7 +2,7 @@ readonly MODULE=${1} readonly DIR=${2} readonly URL=${3} -readonly REV=${5} +readonly BRANCH=${5:+-b ${5}} readonly -i PRINTLEVEL=${6} readonly CLEAR_LINE=$'\E[2K\r' if [[ -e ${DIR} ]]; then @@ -10,7 +10,7 @@ if [[ -e ${DIR} ]]; then return 0 fi if (( PRINTLEVEL > 0 )) print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>" -if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then +if ERR=$(command git clone ${=BRANCH} -q --recursive ${URL} ${DIR} 2>&1); then if (( PRINTLEVEL > 0 )) print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Installed" else print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git clone%f"$'\n'${(F):- ${(f)^ERR}} diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 150b605..ce6cb60 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -3,7 +3,7 @@ readonly MODULE=${1} readonly DIR=${2} readonly URL=${3} readonly TYPE=${4} -readonly REV=${5} +readonly REV=${5:=HEAD} readonly -i PRINTLEVEL=${6} readonly CLEAR_LINE=$'\E[2K\r' if (( PRINTLEVEL > 0 )) print -Rn ${CLEAR_LINE}"Updating ${MODULE}<%= ellipsis %>" @@ -34,7 +34,7 @@ if [[ ${TYPE} == branch ]]; then else LOG_REV=${REV} fi -LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null) +LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} -- 2>/dev/null) if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git checkout%f"$'\n'${(F):- ${(f)^ERR}} return 1 diff --git a/zimfw.zsh b/zimfw.zsh index 9370dd7..0f8c2af 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -117,7 +117,7 @@ The modules are initialized in the same order they are defined. Repository options: %B-b%b|%B--branch%b Use specified branch when installing and updating the module. - Overrides the tag option. Default: %Bmaster%b. + Overrides the tag option. Default: the repository's default branch. %B-t%b|%B--tag%b Use specified tag when installing and updating the module. Overrides the branch option. %B-z%b|%B--frozen%b Don't install or update the module. @@ -146,7 +146,7 @@ Initialization options: fi setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB local zmodule=${1:t} zurl=${1} - local ztype=branch zrev=master + local ztype=branch zrev local -i zdisabled=0 zfrozen=0 local -a zfpaths zfunctions zcmds local zarg zdir @@ -228,7 +228,7 @@ Initialization options: done if (( _zprepare_zargs )); then if (( ! zfrozen )); then - _zmodules_zargs+=(${zmodule} ${zdir} ${zurl} ${ztype} ${zrev} ${_zprintlevel}) + _zmodules_zargs+=(${zmodule} ${zdir} ${zurl} ${ztype} "${zrev}" ${_zprintlevel}) fi else if (( zdisabled )); then @@ -319,7 +319,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2021-01-02 23:37:59 UTC, previous commit is dfbe535)' + print -R 'zimfw version: '${_zversion}' (built at 2021-01-02 23:47:25 UTC, previous commit is 153c547)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -414,7 +414,7 @@ Options: readonly MODULE=\${1} readonly DIR=\${2} readonly URL=\${3} -readonly REV=\${5} +readonly BRANCH=\${5:+-b \${5}} readonly -i PRINTLEVEL=\${6} readonly CLEAR_LINE=$'\E[2K\r' if [[ -e \${DIR} ]]; then @@ -422,7 +422,7 @@ if [[ -e \${DIR} ]]; then return 0 fi if (( PRINTLEVEL > 0 )) print -Rn \${CLEAR_LINE}\"Installing \${MODULE} ...\" -if ERR=\$(command git clone -b \${REV} -q --recursive \${URL} \${DIR} 2>&1); then +if ERR=\$(command git clone \${=BRANCH} -q --recursive \${URL} \${DIR} 2>&1); then if (( PRINTLEVEL > 0 )) print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Installed\" else print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git clone%f\"$'\n'\${(F):- \${(f)^ERR}} @@ -436,7 +436,7 @@ readonly MODULE=\${1} readonly DIR=\${2} readonly URL=\${3} readonly TYPE=\${4} -readonly REV=\${5} +readonly REV=\${5:=HEAD} readonly -i PRINTLEVEL=\${6} readonly CLEAR_LINE=$'\E[2K\r' if (( PRINTLEVEL > 0 )) print -Rn \${CLEAR_LINE}\"Updating \${MODULE} ...\" @@ -467,7 +467,7 @@ if [[ \${TYPE} == branch ]]; then else LOG_REV=\${REV} fi -LOG=\$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..\${LOG_REV} 2>/dev/null) +LOG=\$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..\${LOG_REV} -- 2>/dev/null) if ! ERR=\$(command git checkout -q \${REV} -- 2>&1); then print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git checkout%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 @@ -511,7 +511,7 @@ fi install|update) _zimfw_source_zimrc 1 || return 1 autoload -Uz zargs && \ - zargs -n 9 -P 10 -- ${_zmodules_zargs} -- zsh -c ${ztool} ${1} && \ + zargs -n 9 -P 10 -- "${_zmodules_zargs[@]}" -- zsh -c ${ztool} ${1} && \ _zimfw_print -PR "Done with ${1}. Restart your terminal for any changes to take effect." || return 1 (( _zprintlevel-- )) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile