1
0
Fork 0
mirror of synced 2024-12-25 23:43:20 -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
readonly -i PRINTLEVEL=${1}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7}
readonly TEMP=.zdegit_${RANDOM}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} TEMP=.zdegit_${RANDOM}
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
print_error() {

View file

@ -1,6 +1,6 @@
# This runs in a new shell
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}
print_error() {
@ -13,7 +13,7 @@ print_okay() {
case ${ACTION} in
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
else
print_error 'Error during git clone' ${ERR}
@ -21,49 +21,46 @@ case ${ACTION} in
fi
;;
update)
if ! builtin cd -q ${DIR} 2>/dev/null; then
print_error "Error during cd ${DIR}"
return 1
fi
if [[ ${PWD:A} != ${"$(command git rev-parse --show-toplevel 2>/dev/null)":A} ]]; then
readonly GIT_DIR=${DIR}/.git
if [[ ! -d ${GIT_DIR} ]]; 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"
fi
return 0
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."
return 1
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}
return 1
fi
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'
return 0
fi
elif [[ -z ${REV} ]]; then
# 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}
return 1
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
if [[ ${TYPE} == branch ]]; then
LOG_REV=${REV}@{u}
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)
if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then
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 -C ${DIR} --git-dir=${GIT_DIR} checkout -q ${REV} -- 2>&1); then
print_error 'Error during git checkout' ${ERR}
return 1
fi
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}
return 1
fi
@ -72,9 +69,11 @@ case ${ACTION} in
else
OUT="Updating to ${TYPE} ${REV}"
fi
if ! ERR=$(command git submodule update --init --recursive -q 2>&1); then
print_error 'Error during git submodule update' ${ERR}
return 1
if [[ -n ${SUBMODULES} ]]; then
if ! ERR=$(command git -C ${DIR} --git-dir=${GIT_DIR} submodule update --init --recursive -q -- 2>&1); then
print_error 'Error during git submodule update' ${ERR}
return 1
fi
fi
print_okay ${OUT} ${LOG}
;;

View file

@ -373,7 +373,7 @@ _zimfw_compile() {
}
_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 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a)
@ -484,8 +484,7 @@ _zimfw_run_tool() {
case ${ztool} in
degit) zcmd="# This runs in a new shell
readonly -i PRINTLEVEL=\${1}
readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7}
readonly TEMP=.zdegit_\${RANDOM}
readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} TEMP=.zdegit_\${RANDOM}
readonly TARBALL_TARGET=\${DIR}/\${TEMP}_tarball.tar.gz INFO_TARGET=\${DIR}/.zdegit
print_error() {
@ -627,7 +626,7 @@ esac
" ;;
git) zcmd="# This runs in a new shell
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}
print_error() {
@ -640,7 +639,7 @@ print_okay() {
case \${ACTION} in
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
else
print_error 'Error during git clone' \${ERR}
@ -648,49 +647,46 @@ case \${ACTION} in
fi
;;
update)
if ! builtin cd -q \${DIR} 2>/dev/null; then
print_error \"Error during cd \${DIR}\"
return 1
fi
if [[ \${PWD:A} != \${\"\$(command git rev-parse --show-toplevel 2>/dev/null)\":A} ]]; then
readonly GIT_DIR=\${DIR}/.git
if [[ ! -d \${GIT_DIR} ]]; 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\"
fi
return 0
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.\"
return 1
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}
return 1
fi
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'
return 0
fi
elif [[ -z \${REV} ]]; then
# 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}
return 1
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
if [[ \${TYPE} == branch ]]; then
LOG_REV=\${REV}@{u}
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)
if ! ERR=\$(command git checkout -q \${REV} -- 2>&1); then
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 -C \${DIR} --git-dir=\${GIT_DIR} checkout -q \${REV} -- 2>&1); then
print_error 'Error during git checkout' \${ERR}
return 1
fi
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}
return 1
fi
@ -699,9 +695,11 @@ case \${ACTION} in
else
OUT=\"Updating to \${TYPE} \${REV}\"
fi
if ! ERR=\$(command git submodule update --init --recursive -q 2>&1); then
print_error 'Error during git submodule update' \${ERR}
return 1
if [[ -n \${SUBMODULES} ]]; then
if ! ERR=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} submodule update --init --recursive -q -- 2>&1); then
print_error 'Error during git submodule update' \${ERR}
return 1
fi
fi
print_okay \${OUT} \${LOG}
;;