1
0
Fork 0
mirror of synced 2024-11-22 15:25:34 -05:00

Use git -C instead of changing to the module dir

when doing update using the git tool.
This commit is contained in:
Eric Nielsen 2021-11-10 22:50:17 -05:00
parent 6e7c6a269d
commit cd71c8d228
No known key found for this signature in database
GPG key ID: 47D1DBFA0765A1FB
3 changed files with 37 additions and 41 deletions

View file

@ -1,7 +1,6 @@
# This runs in a new shell # This runs in a new shell
readonly -i PRINTLEVEL=${1} readonly -i PRINTLEVEL=${1}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} TEMP=.zdegit_${RANDOM}
readonly TEMP=.zdegit_${RANDOM}
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
print_error() { print_error() {

View file

@ -1,6 +1,6 @@
# This runs in a new shell # This runs in a new shell
readonly -i PRINTLEVEL=${1} readonly -i PRINTLEVEL=${1}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} TYPE=${6:=branch} readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} TYPE=${6:=branch} SUBMODULES=1
REV=${7} REV=${7}
print_error() { print_error() {
@ -13,7 +13,7 @@ print_okay() {
case ${ACTION} in case ${ACTION} in
install) install)
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false --recursive ${URL} ${DIR} 2>&1); then if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${SUBMODULES:+--recursive} -- ${URL} ${DIR} 2>&1); then
print_okay Installed print_okay Installed
else else
print_error 'Error during git clone' ${ERR} print_error 'Error during git clone' ${ERR}
@ -21,49 +21,46 @@ case ${ACTION} in
fi fi
;; ;;
update) update)
if ! builtin cd -q ${DIR} 2>/dev/null; then readonly GIT_DIR=${DIR}/.git
print_error "Error during cd ${DIR}" if [[ ! -d ${GIT_DIR} ]]; then
return 1
fi
if [[ ${PWD:A} != ${"$(command git rev-parse --show-toplevel 2>/dev/null)":A} ]]; then
if (( PRINTLEVEL > 0 )); then if (( PRINTLEVEL > 0 )); then
print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b Module was not installed using git. Will not try to update. You can disable this with the zmodule option -z|--frozen.%f" print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b Module was not installed using git. Will not try to update. You can disable this with the zmodule option -z|--frozen.%f"
fi fi
return 0 return 0
fi fi
if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then if [[ ${URL} != $(command git -C ${DIR} --git-dir=${GIT_DIR} config --get remote.origin.url) ]]; then
print_error "URL does not match. Expected ${URL}. Will not try to update." print_error "URL does not match. Expected ${URL}. Will not try to update."
return 1 return 1
fi fi
if ! ERR=$(command git fetch -pq origin 2>&1); then if ! ERR=$(command git -C ${DIR} --git-dir=${GIT_DIR} fetch -pq origin 2>&1); then
print_error 'Error during git fetch' ${ERR} print_error 'Error during git fetch' ${ERR}
return 1 return 1
fi fi
if [[ ${TYPE} == tag ]]; then if [[ ${TYPE} == tag ]]; then
if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then if [[ ${REV} == $(command git -C ${DIR} --git-dir=${GIT_DIR} describe --tags --exact-match 2>/dev/null) ]]; then
print_okay 'Already up to date' print_okay 'Already up to date'
return 0 return 0
fi fi
elif [[ -z ${REV} ]]; then elif [[ -z ${REV} ]]; then
# Get HEAD remote branch # Get HEAD remote branch
if ! ERR=$(command git remote set-head origin -a 2>&1); then if ! ERR=$(command git -C ${DIR} --git-dir=${GIT_DIR} remote set-head origin -a 2>&1); then
print_error 'Error during git remote set-head' ${ERR} print_error 'Error during git remote set-head' ${ERR}
return 1 return 1
fi fi
REV=${$(command git symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1 REV=${$(command git -C ${DIR} --git-dir=${GIT_DIR} symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1
fi fi
if [[ ${TYPE} == branch ]]; then if [[ ${TYPE} == branch ]]; then
LOG_REV=${REV}@{u} LOG_REV=${REV}@{u}
else else
LOG_REV=${REV} LOG_REV=${REV}
fi 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 -C ${DIR} --git-dir=${GIT_DIR} 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 if ! ERR=$(command git -C ${DIR} --git-dir=${GIT_DIR} checkout -q ${REV} -- 2>&1); then
print_error 'Error during git checkout' ${ERR} print_error 'Error during git checkout' ${ERR}
return 1 return 1
fi fi
if [[ ${TYPE} == branch ]]; then if [[ ${TYPE} == branch ]]; then
if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then if ! OUT=$(command git -C ${DIR} --git-dir=${GIT_DIR} merge --ff-only --no-progress -n 2>&1); then
print_error 'Error during git merge' ${OUT} print_error 'Error during git merge' ${OUT}
return 1 return 1
fi fi
@ -72,9 +69,11 @@ case ${ACTION} in
else else
OUT="Updating to ${TYPE} ${REV}" OUT="Updating to ${TYPE} ${REV}"
fi fi
if ! ERR=$(command git submodule update --init --recursive -q 2>&1); then if [[ -n ${SUBMODULES} ]]; then
print_error 'Error during git submodule update' ${ERR} if ! ERR=$(command git -C ${DIR} --git-dir=${GIT_DIR} submodule update --init --recursive -q -- 2>&1); then
return 1 print_error 'Error during git submodule update' ${ERR}
return 1
fi
fi fi
print_okay ${OUT} ${LOG} print_okay ${OUT} ${LOG}
;; ;;

View file

@ -373,7 +373,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2021-11-09 01:04:00 UTC, previous commit is 503f2da)' print -R 'zimfw version: '${_zversion}' (built at 2021-11-11 03:49:14 UTC, previous commit is 6e7c6a2)'
print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION} print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a) print -R 'System info: '$(command uname -a)
@ -484,8 +484,7 @@ _zimfw_run_tool() {
case ${ztool} in case ${ztool} in
degit) zcmd="# This runs in a new shell degit) zcmd="# This runs in a new shell
readonly -i PRINTLEVEL=\${1} readonly -i PRINTLEVEL=\${1}
readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} TEMP=.zdegit_\${RANDOM}
readonly TEMP=.zdegit_\${RANDOM}
readonly TARBALL_TARGET=\${DIR}/\${TEMP}_tarball.tar.gz INFO_TARGET=\${DIR}/.zdegit readonly TARBALL_TARGET=\${DIR}/\${TEMP}_tarball.tar.gz INFO_TARGET=\${DIR}/.zdegit
print_error() { print_error() {
@ -627,7 +626,7 @@ esac
" ;; " ;;
git) zcmd="# This runs in a new shell git) zcmd="# This runs in a new shell
readonly -i PRINTLEVEL=\${1} readonly -i PRINTLEVEL=\${1}
readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} TYPE=\${6:=branch} readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} TYPE=\${6:=branch} SUBMODULES=1
REV=\${7} REV=\${7}
print_error() { print_error() {
@ -640,7 +639,7 @@ print_okay() {
case \${ACTION} in case \${ACTION} in
install) install)
if ERR=\$(command git clone \${REV:+-b} \${REV} -q --config core.autocrlf=false --recursive \${URL} \${DIR} 2>&1); then if ERR=\$(command git clone \${REV:+-b} \${REV} -q --config core.autocrlf=false \${SUBMODULES:+--recursive} -- \${URL} \${DIR} 2>&1); then
print_okay Installed print_okay Installed
else else
print_error 'Error during git clone' \${ERR} print_error 'Error during git clone' \${ERR}
@ -648,49 +647,46 @@ case \${ACTION} in
fi fi
;; ;;
update) update)
if ! builtin cd -q \${DIR} 2>/dev/null; then readonly GIT_DIR=\${DIR}/.git
print_error \"Error during cd \${DIR}\" if [[ ! -d \${GIT_DIR} ]]; then
return 1
fi
if [[ \${PWD:A} != \${\"\$(command git rev-parse --show-toplevel 2>/dev/null)\":A} ]]; then
if (( PRINTLEVEL > 0 )); then if (( PRINTLEVEL > 0 )); then
print -u2 -PR $'\E[2K\r'\"%F{yellow}! %B\${MODULE}:%b Module was not installed using git. Will not try to update. You can disable this with the zmodule option -z|--frozen.%f\" print -u2 -PR $'\E[2K\r'\"%F{yellow}! %B\${MODULE}:%b Module was not installed using git. Will not try to update. You can disable this with the zmodule option -z|--frozen.%f\"
fi fi
return 0 return 0
fi fi
if [[ \${URL} != \$(command git config --get remote.origin.url) ]]; then if [[ \${URL} != \$(command git -C \${DIR} --git-dir=\${GIT_DIR} config --get remote.origin.url) ]]; then
print_error \"URL does not match. Expected \${URL}. Will not try to update.\" print_error \"URL does not match. Expected \${URL}. Will not try to update.\"
return 1 return 1
fi fi
if ! ERR=\$(command git fetch -pq origin 2>&1); then if ! ERR=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} fetch -pq origin 2>&1); then
print_error 'Error during git fetch' \${ERR} print_error 'Error during git fetch' \${ERR}
return 1 return 1
fi fi
if [[ \${TYPE} == tag ]]; then if [[ \${TYPE} == tag ]]; then
if [[ \${REV} == \$(command git describe --tags --exact-match 2>/dev/null) ]]; then if [[ \${REV} == \$(command git -C \${DIR} --git-dir=\${GIT_DIR} describe --tags --exact-match 2>/dev/null) ]]; then
print_okay 'Already up to date' print_okay 'Already up to date'
return 0 return 0
fi fi
elif [[ -z \${REV} ]]; then elif [[ -z \${REV} ]]; then
# Get HEAD remote branch # Get HEAD remote branch
if ! ERR=\$(command git remote set-head origin -a 2>&1); then if ! ERR=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} remote set-head origin -a 2>&1); then
print_error 'Error during git remote set-head' \${ERR} print_error 'Error during git remote set-head' \${ERR}
return 1 return 1
fi fi
REV=\${\$(command git symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1 REV=\${\$(command git -C \${DIR} --git-dir=\${GIT_DIR} symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1
fi fi
if [[ \${TYPE} == branch ]]; then if [[ \${TYPE} == branch ]]; then
LOG_REV=\${REV}@{u} LOG_REV=\${REV}@{u}
else else
LOG_REV=\${REV} LOG_REV=\${REV}
fi 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 -C \${DIR} --git-dir=\${GIT_DIR} 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 if ! ERR=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} checkout -q \${REV} -- 2>&1); then
print_error 'Error during git checkout' \${ERR} print_error 'Error during git checkout' \${ERR}
return 1 return 1
fi fi
if [[ \${TYPE} == branch ]]; then if [[ \${TYPE} == branch ]]; then
if ! OUT=\$(command git merge --ff-only --no-progress -n 2>&1); then if ! OUT=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} merge --ff-only --no-progress -n 2>&1); then
print_error 'Error during git merge' \${OUT} print_error 'Error during git merge' \${OUT}
return 1 return 1
fi fi
@ -699,9 +695,11 @@ case \${ACTION} in
else else
OUT=\"Updating to \${TYPE} \${REV}\" OUT=\"Updating to \${TYPE} \${REV}\"
fi fi
if ! ERR=\$(command git submodule update --init --recursive -q 2>&1); then if [[ -n \${SUBMODULES} ]]; then
print_error 'Error during git submodule update' \${ERR} if ! ERR=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} submodule update --init --recursive -q -- 2>&1); then
return 1 print_error 'Error during git submodule update' \${ERR}
return 1
fi
fi fi
print_okay \${OUT} \${LOG} print_okay \${OUT} \${LOG}
;; ;;