Pre check module before running tool
Check if module is correctly installed before running any other action on the module. See #542
This commit is contained in:
parent
7f3491b1bb
commit
880ed131a1
6 changed files with 97 additions and 81 deletions
|
@ -4,7 +4,7 @@ _zimfw_download_tarball() {
|
||||||
readonly REPO=${match[4]%.git}
|
readonly REPO=${match[4]%.git}
|
||||||
fi
|
fi
|
||||||
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
|
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
|
||||||
_zimfw_print_error ${URL}$' is not a valid URL. Will not try to '${_zaction}$'. The zimfw degit tool only supports GitHub URLs. Use zmodule option <%= bold %>--use git<%= normalred %> to use git instead.'
|
_zimfw_print_error ${URL}$' is not a valid URL. Will not try to '${ACTION}$'. The zimfw degit tool only supports GitHub URLs. Use zmodule option <%= bold %>--use git<%= normalred %> to use git instead.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
|
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
|
||||||
|
@ -12,14 +12,14 @@ _zimfw_download_tarball() {
|
||||||
if [[ -r ${INFO_TARGET} ]]; then
|
if [[ -r ${INFO_TARGET} ]]; then
|
||||||
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
||||||
if [[ ${URL} != ${INFO[1]} ]]; then
|
if [[ ${URL} != ${INFO[1]} ]]; then
|
||||||
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${_zaction}."
|
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${ACTION}."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Previous REV is in line 2, reserved for future use.
|
# Previous REV is in line 2, reserved for future use.
|
||||||
readonly INFO_HEADER=${INFO[3]}
|
readonly INFO_HEADER=${INFO[3]}
|
||||||
fi
|
fi
|
||||||
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
|
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
if [[ -z ${INFO_HEADER} ]] return 0
|
if [[ -z ${INFO_HEADER} ]] return 0
|
||||||
if (( ${+commands[curl]} )); then
|
if (( ${+commands[curl]} )); then
|
||||||
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
|
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
|
||||||
|
@ -57,7 +57,7 @@ _zimfw_download_tarball() {
|
||||||
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
|
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
command touch ${TARBALL_TARGET} # Update available
|
command touch ${TARBALL_TARGET} # Update available
|
||||||
else
|
else
|
||||||
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
|
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
|
||||||
|
@ -86,10 +86,19 @@ _zimfw_untar_tarball() {
|
||||||
|
|
||||||
_zimfw_tool_degit() {
|
_zimfw_tool_degit() {
|
||||||
# This runs in a subshell
|
# This runs in a subshell
|
||||||
readonly -i SUBMODULES=${5}
|
readonly -i SUBMODULES=${6}
|
||||||
readonly DIR=${1} URL=${2} REV=${4} ONPULL=${6} TEMP=.zdegit_${sysparams[pid]}
|
readonly ACTION=${1} DIR=${2} URL=${3} REV=${5} ONPULL=${7} TEMP=.zdegit_${sysparams[pid]}
|
||||||
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
|
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
|
||||||
case ${_zaction} in
|
case ${ACTION} in
|
||||||
|
pre)
|
||||||
|
if [[ -e ${DIR} ]]; then
|
||||||
|
if [[ ! -r ${INFO_TARGET} ]]; then
|
||||||
|
_zimfw_print_error $'Module was not installed using zimfw\'s degit. Use zmodule option <%= bold %>-z<%= normalred %>|<%= bold %>--frozen<%= normalred %> to disable this error.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
install)
|
install)
|
||||||
{
|
{
|
||||||
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
|
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
|
||||||
|
@ -101,14 +110,10 @@ _zimfw_tool_degit() {
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
check|update)
|
check|update)
|
||||||
if [[ ! -r ${INFO_TARGET} ]]; then
|
|
||||||
_zimfw_print_warn $'Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.'
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
readonly DIR_NEW=${DIR}${TEMP}
|
readonly DIR_NEW=${DIR}${TEMP}
|
||||||
{
|
{
|
||||||
_zimfw_download_tarball || return 1
|
_zimfw_download_tarball || return 1
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
if [[ -e ${TARBALL_TARGET} ]]; then
|
if [[ -e ${TARBALL_TARGET} ]]; then
|
||||||
_zimfw_print_okay 'Update available'
|
_zimfw_print_okay 'Update available'
|
||||||
return 4
|
return 4
|
||||||
|
|
|
@ -1,9 +1,21 @@
|
||||||
_zimfw_tool_git() {
|
_zimfw_tool_git() {
|
||||||
# This runs in a subshell
|
# This runs in a subshell
|
||||||
readonly -i SUBMODULES=${5}
|
readonly -i SUBMODULES=${6}
|
||||||
readonly DIR=${1} URL=${2} TYPE=${3} ONPULL=${6}
|
readonly ACTION=${1} DIR=${2} URL=${3} TYPE=${4} ONPULL=${7}
|
||||||
REV=${4}
|
REV=${5}
|
||||||
case ${_zaction} in
|
case ${ACTION} in
|
||||||
|
pre)
|
||||||
|
if [[ -e ${DIR} ]]; then
|
||||||
|
if [[ ! -r ${DIR}/.git ]]; then
|
||||||
|
_zimfw_print_error $'Module was not installed using git. Use zmodule option <%= bold %>-z<%= normalred %>|<%= bold %>--frozen<%= normalred %> to disable this error.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
|
||||||
|
_zimfw_print_error 'The git URL does not match. Expected '${URL}.$' Use zmodule option <%= bold %>-z<%= normalred %>|<%= bold %>--frozen<%= normalred %> to disable this error.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
install)
|
install)
|
||||||
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
|
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
|
||||||
_zimfw_pull_print_okay Installed
|
_zimfw_pull_print_okay Installed
|
||||||
|
@ -13,14 +25,6 @@ _zimfw_tool_git() {
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
check|update)
|
check|update)
|
||||||
if [[ ! -r ${DIR}/.git ]]; then
|
|
||||||
_zimfw_print_warn 'Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.'
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
|
|
||||||
_zimfw_print_error "The git URL does not match. Expected ${URL}. Will not try to ${_zaction}."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
|
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
|
||||||
_zimfw_print_error 'Error during git fetch' ${ERR}
|
_zimfw_print_error 'Error during git fetch' ${ERR}
|
||||||
return 1
|
return 1
|
||||||
|
@ -40,7 +44,7 @@ _zimfw_tool_git() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
TO_REV=${REV}@{u}
|
TO_REV=${REV}@{u}
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${TO_REV} -- 2>/dev/null)
|
readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${TO_REV} -- 2>/dev/null)
|
||||||
if (( BEHIND )); then
|
if (( BEHIND )); then
|
||||||
_zimfw_print_okay "Update available [behind ${BEHIND}]"
|
_zimfw_print_okay "Update available [behind ${BEHIND}]"
|
||||||
|
@ -52,7 +56,7 @@ _zimfw_tool_git() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
|
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
_zimfw_print_okay 'Already up to date' 1
|
_zimfw_print_okay 'Already up to date' 1
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -60,7 +64,7 @@ _zimfw_tool_git() {
|
||||||
return ${?}
|
return ${?}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
_zimfw_print_okay 'Update available'
|
_zimfw_print_okay 'Update available'
|
||||||
return 4
|
return 4
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
_zimfw_tool_mkdir() {
|
_zimfw_tool_mkdir() {
|
||||||
# This runs in a subshell
|
# This runs in a subshell
|
||||||
readonly -i SUBMODULES=${5}
|
readonly -i SUBMODULES=${6}
|
||||||
readonly DIR=${1} TYPE=${3} REV=${4} ONPULL=${6}
|
readonly ACTION=${1} DIR=${2} TYPE=${4} REV=${5} ONPULL=${7}
|
||||||
|
if [[ ${ACTION} == pre ]] return 0
|
||||||
if [[ -n ${REV} ]]; then
|
if [[ -n ${REV} ]]; then
|
||||||
_zimfw_print_warn $'The zmodule option <%= bold %>-'${TYPE[1]}$'<%= normalyellow %>|<%= bold %>--'${TYPE}$'<%= normalyellow %> has no effect when using the mkdir tool'
|
_zimfw_print_warn $'The zmodule option <%= bold %>-'${TYPE[1]}$'<%= normalyellow %>|<%= bold %>--'${TYPE}$'<%= normalyellow %> has no effect when using the mkdir tool'
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -8,6 +8,13 @@ _zimfw_run_tool() {
|
||||||
_zimfw_print_okay 'Skipping frozen module' 1
|
_zimfw_print_okay 'Skipping frozen module' 1
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
local -r ztool=${_ztools[${_zname}]}
|
||||||
|
if [[ ${ztool} != (degit|git|mkdir) ]]; then
|
||||||
|
_zimfw_print_error "Unknown tool ${ztool}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
set "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
|
||||||
|
_zimfw_tool_${ztool} pre "${@}" || return 1
|
||||||
case ${_zaction} in
|
case ${_zaction} in
|
||||||
install)
|
install)
|
||||||
if [[ -e ${_zdirs[${_zname}]} ]]; then
|
if [[ -e ${_zdirs[${_zname}]} ]]; then
|
||||||
|
@ -32,14 +39,5 @@ _zimfw_run_tool() {
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
local -r ztool=${_ztools[${_zname}]}
|
_zimfw_tool_${ztool} ${_zaction} "${@}"
|
||||||
case ${ztool} in
|
|
||||||
degit|git|mkdir)
|
|
||||||
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
_zimfw_print_error "Unknown tool ${ztool}"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Zim
|
||||||
:bold, :normal, :red, :normalred, :yellow, :normalyellow, :clear_line, :ellipsis, :okay, :warn, :error
|
:bold, :normal, :red, :normalred, :yellow, :normalyellow, :clear_line, :ellipsis, :okay, :warn, :error
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@version = "1.14.0"
|
@version = "1.15.0-SNAPSHOT"
|
||||||
@home = "${ZDOTDIR:-${HOME}}"
|
@home = "${ZDOTDIR:-${HOME}}"
|
||||||
@min_zsh_version = "5.2"
|
@min_zsh_version = "5.2"
|
||||||
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
|
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
|
||||||
|
|
90
zimfw.zsh
90
zimfw.zsh
|
@ -462,7 +462,7 @@ _zimfw_compile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_info() {
|
_zimfw_info() {
|
||||||
print -R 'zimfw version: '${_zversion}' (built at 2024-06-25 18:20:18 UTC, previous commit is 6166fce)'
|
print -R 'zimfw version: '${_zversion}' (built at 2024-08-20 13:01:29 UTC, previous commit is 7f3491b)'
|
||||||
local zparam
|
local zparam
|
||||||
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do
|
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do
|
||||||
print -R ${(r.22....:.)zparam}${(P)zparam}
|
print -R ${(r.22....:.)zparam}${(P)zparam}
|
||||||
|
@ -590,7 +590,7 @@ _zimfw_download_tarball() {
|
||||||
readonly REPO=${match[4]%.git}
|
readonly REPO=${match[4]%.git}
|
||||||
fi
|
fi
|
||||||
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
|
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
|
||||||
_zimfw_print_error ${URL}$' is not a valid URL. Will not try to '${_zaction}$'. The zimfw degit tool only supports GitHub URLs. Use zmodule option \E[1m--use git\E[0;31m to use git instead.'
|
_zimfw_print_error ${URL}$' is not a valid URL. Will not try to '${ACTION}$'. The zimfw degit tool only supports GitHub URLs. Use zmodule option \E[1m--use git\E[0;31m to use git instead.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
|
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
|
||||||
|
@ -598,14 +598,14 @@ _zimfw_download_tarball() {
|
||||||
if [[ -r ${INFO_TARGET} ]]; then
|
if [[ -r ${INFO_TARGET} ]]; then
|
||||||
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
||||||
if [[ ${URL} != ${INFO[1]} ]]; then
|
if [[ ${URL} != ${INFO[1]} ]]; then
|
||||||
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${_zaction}."
|
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${ACTION}."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Previous REV is in line 2, reserved for future use.
|
# Previous REV is in line 2, reserved for future use.
|
||||||
readonly INFO_HEADER=${INFO[3]}
|
readonly INFO_HEADER=${INFO[3]}
|
||||||
fi
|
fi
|
||||||
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
|
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
if [[ -z ${INFO_HEADER} ]] return 0
|
if [[ -z ${INFO_HEADER} ]] return 0
|
||||||
if (( ${+commands[curl]} )); then
|
if (( ${+commands[curl]} )); then
|
||||||
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
|
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
|
||||||
|
@ -643,7 +643,7 @@ _zimfw_download_tarball() {
|
||||||
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
|
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
command touch ${TARBALL_TARGET} # Update available
|
command touch ${TARBALL_TARGET} # Update available
|
||||||
else
|
else
|
||||||
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
|
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
|
||||||
|
@ -672,10 +672,19 @@ _zimfw_untar_tarball() {
|
||||||
|
|
||||||
_zimfw_tool_degit() {
|
_zimfw_tool_degit() {
|
||||||
# This runs in a subshell
|
# This runs in a subshell
|
||||||
readonly -i SUBMODULES=${5}
|
readonly -i SUBMODULES=${6}
|
||||||
readonly DIR=${1} URL=${2} REV=${4} ONPULL=${6} TEMP=.zdegit_${sysparams[pid]}
|
readonly ACTION=${1} DIR=${2} URL=${3} REV=${5} ONPULL=${7} TEMP=.zdegit_${sysparams[pid]}
|
||||||
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
|
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
|
||||||
case ${_zaction} in
|
case ${ACTION} in
|
||||||
|
pre)
|
||||||
|
if [[ -e ${DIR} ]]; then
|
||||||
|
if [[ ! -r ${INFO_TARGET} ]]; then
|
||||||
|
_zimfw_print_error $'Module was not installed using zimfw\'s degit. Use zmodule option \E[1m-z\E[0;31m|\E[1m--frozen\E[0;31m to disable this error.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
install)
|
install)
|
||||||
{
|
{
|
||||||
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
|
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
|
||||||
|
@ -687,14 +696,10 @@ _zimfw_tool_degit() {
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
check|update)
|
check|update)
|
||||||
if [[ ! -r ${INFO_TARGET} ]]; then
|
|
||||||
_zimfw_print_warn $'Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.'
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
readonly DIR_NEW=${DIR}${TEMP}
|
readonly DIR_NEW=${DIR}${TEMP}
|
||||||
{
|
{
|
||||||
_zimfw_download_tarball || return 1
|
_zimfw_download_tarball || return 1
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
if [[ -e ${TARBALL_TARGET} ]]; then
|
if [[ -e ${TARBALL_TARGET} ]]; then
|
||||||
_zimfw_print_okay 'Update available'
|
_zimfw_print_okay 'Update available'
|
||||||
return 4
|
return 4
|
||||||
|
@ -732,10 +737,22 @@ _zimfw_tool_degit() {
|
||||||
|
|
||||||
_zimfw_tool_git() {
|
_zimfw_tool_git() {
|
||||||
# This runs in a subshell
|
# This runs in a subshell
|
||||||
readonly -i SUBMODULES=${5}
|
readonly -i SUBMODULES=${6}
|
||||||
readonly DIR=${1} URL=${2} TYPE=${3} ONPULL=${6}
|
readonly ACTION=${1} DIR=${2} URL=${3} TYPE=${4} ONPULL=${7}
|
||||||
REV=${4}
|
REV=${5}
|
||||||
case ${_zaction} in
|
case ${ACTION} in
|
||||||
|
pre)
|
||||||
|
if [[ -e ${DIR} ]]; then
|
||||||
|
if [[ ! -r ${DIR}/.git ]]; then
|
||||||
|
_zimfw_print_error $'Module was not installed using git. Use zmodule option \E[1m-z\E[0;31m|\E[1m--frozen\E[0;31m to disable this error.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
|
||||||
|
_zimfw_print_error 'The git URL does not match. Expected '${URL}.$' Use zmodule option \E[1m-z\E[0;31m|\E[1m--frozen\E[0;31m to disable this error.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
install)
|
install)
|
||||||
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
|
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
|
||||||
_zimfw_pull_print_okay Installed
|
_zimfw_pull_print_okay Installed
|
||||||
|
@ -745,14 +762,6 @@ _zimfw_tool_git() {
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
check|update)
|
check|update)
|
||||||
if [[ ! -r ${DIR}/.git ]]; then
|
|
||||||
_zimfw_print_warn 'Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.'
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
|
|
||||||
_zimfw_print_error "The git URL does not match. Expected ${URL}. Will not try to ${_zaction}."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
|
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
|
||||||
_zimfw_print_error 'Error during git fetch' ${ERR}
|
_zimfw_print_error 'Error during git fetch' ${ERR}
|
||||||
return 1
|
return 1
|
||||||
|
@ -772,7 +781,7 @@ _zimfw_tool_git() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
TO_REV=${REV}@{u}
|
TO_REV=${REV}@{u}
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${TO_REV} -- 2>/dev/null)
|
readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${TO_REV} -- 2>/dev/null)
|
||||||
if (( BEHIND )); then
|
if (( BEHIND )); then
|
||||||
_zimfw_print_okay "Update available [behind ${BEHIND}]"
|
_zimfw_print_okay "Update available [behind ${BEHIND}]"
|
||||||
|
@ -784,7 +793,7 @@ _zimfw_tool_git() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
|
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
_zimfw_print_okay 'Already up to date' 1
|
_zimfw_print_okay 'Already up to date' 1
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -792,7 +801,7 @@ _zimfw_tool_git() {
|
||||||
return ${?}
|
return ${?}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ ${_zaction} == check ]]; then
|
if [[ ${ACTION} == check ]]; then
|
||||||
_zimfw_print_okay 'Update available'
|
_zimfw_print_okay 'Update available'
|
||||||
return 4
|
return 4
|
||||||
fi
|
fi
|
||||||
|
@ -826,8 +835,9 @@ _zimfw_tool_git() {
|
||||||
|
|
||||||
_zimfw_tool_mkdir() {
|
_zimfw_tool_mkdir() {
|
||||||
# This runs in a subshell
|
# This runs in a subshell
|
||||||
readonly -i SUBMODULES=${5}
|
readonly -i SUBMODULES=${6}
|
||||||
readonly DIR=${1} TYPE=${3} REV=${4} ONPULL=${6}
|
readonly ACTION=${1} DIR=${2} TYPE=${4} REV=${5} ONPULL=${7}
|
||||||
|
if [[ ${ACTION} == pre ]] return 0
|
||||||
if [[ -n ${REV} ]]; then
|
if [[ -n ${REV} ]]; then
|
||||||
_zimfw_print_warn $'The zmodule option \E[1m-'${TYPE[1]}$'\E[0;33m|\E[1m--'${TYPE}$'\E[0;33m has no effect when using the mkdir tool'
|
_zimfw_print_warn $'The zmodule option \E[1m-'${TYPE[1]}$'\E[0;33m|\E[1m--'${TYPE}$'\E[0;33m has no effect when using the mkdir tool'
|
||||||
fi
|
fi
|
||||||
|
@ -849,6 +859,13 @@ _zimfw_run_tool() {
|
||||||
_zimfw_print_okay 'Skipping frozen module' 1
|
_zimfw_print_okay 'Skipping frozen module' 1
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
local -r ztool=${_ztools[${_zname}]}
|
||||||
|
if [[ ${ztool} != (degit|git|mkdir) ]]; then
|
||||||
|
_zimfw_print_error "Unknown tool ${ztool}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
set "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
|
||||||
|
_zimfw_tool_${ztool} pre "${@}" || return 1
|
||||||
case ${_zaction} in
|
case ${_zaction} in
|
||||||
install)
|
install)
|
||||||
if [[ -e ${_zdirs[${_zname}]} ]]; then
|
if [[ -e ${_zdirs[${_zname}]} ]]; then
|
||||||
|
@ -873,16 +890,7 @@ _zimfw_run_tool() {
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
local -r ztool=${_ztools[${_zname}]}
|
_zimfw_tool_${ztool} ${_zaction} "${@}"
|
||||||
case ${ztool} in
|
|
||||||
degit|git|mkdir)
|
|
||||||
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
_zimfw_print_error "Unknown tool ${ztool}"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_run_tool_action() {
|
_zimfw_run_tool_action() {
|
||||||
|
@ -894,7 +902,7 @@ _zimfw_run_tool_action() {
|
||||||
|
|
||||||
zimfw() {
|
zimfw() {
|
||||||
builtin emulate -L zsh -o EXTENDED_GLOB
|
builtin emulate -L zsh -o EXTENDED_GLOB
|
||||||
local -r _zversion='1.14.0' zusage=$'Usage: \E[1m'${0}$'\E[0m <action> [\E[1m-q\E[0m|\E[1m-v\E[0m]
|
local -r _zversion='1.15.0-SNAPSHOT' zusage=$'Usage: \E[1m'${0}$'\E[0m <action> [\E[1m-q\E[0m|\E[1m-v\E[0m]
|
||||||
|
|
||||||
Actions:
|
Actions:
|
||||||
\E[1mbuild\E[0m Build \E[1m'${ZIM_HOME}$'/init.zsh\E[0m and \E[1m'${ZIM_HOME}$'/login_init.zsh\E[0m.
|
\E[1mbuild\E[0m Build \E[1m'${ZIM_HOME}$'/init.zsh\E[0m and \E[1m'${ZIM_HOME}$'/login_init.zsh\E[0m.
|
||||||
|
|
Loading…
Reference in a new issue