1
0
Fork 0
mirror of synced 2024-11-26 17:25:35 -05:00

.git can be either a directory or a file

Git submodules usually have .git as file, actually. Zim modules should
not be git submodules, but we don't want Zim to be too smart here either.
See https://git-scm.com/docs/gitrepository-layout#_description
This commit is contained in:
Eric Nielsen 2021-11-11 13:46:28 -05:00
parent cd71c8d228
commit e060934a9e
No known key found for this signature in database
GPG key ID: 47D1DBFA0765A1FB
2 changed files with 21 additions and 23 deletions

View file

@ -21,46 +21,45 @@ case ${ACTION} in
fi fi
;; ;;
update) update)
readonly GIT_DIR=${DIR}/.git if [[ ! -r ${DIR}/.git ]]; then
if [[ ! -d ${GIT_DIR} ]]; 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 -C ${DIR} --git-dir=${GIT_DIR} config --get remote.origin.url) ]]; then if [[ ${URL} != $(command git -C ${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 -C ${DIR} --git-dir=${GIT_DIR} fetch -pq origin 2>&1); then if ! ERR=$(command git -C ${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 -C ${DIR} --git-dir=${GIT_DIR} describe --tags --exact-match 2>/dev/null) ]]; then if [[ ${REV} == $(command git -C ${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 -C ${DIR} --git-dir=${GIT_DIR} remote set-head origin -a 2>&1); then if ! ERR=$(command git -C ${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 -C ${DIR} --git-dir=${GIT_DIR} symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1 REV=${$(command git -C ${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 -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) LOG=$(command git -C ${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 if ! ERR=$(command git -C ${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 -C ${DIR} --git-dir=${GIT_DIR} merge --ff-only --no-progress -n 2>&1); then if ! OUT=$(command git -C ${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
@ -70,7 +69,7 @@ case ${ACTION} in
OUT="Updating to ${TYPE} ${REV}" OUT="Updating to ${TYPE} ${REV}"
fi fi
if [[ -n ${SUBMODULES} ]]; then if [[ -n ${SUBMODULES} ]]; then
if ! ERR=$(command git -C ${DIR} --git-dir=${GIT_DIR} submodule update --init --recursive -q -- 2>&1); then if ! ERR=$(command git -C ${DIR} submodule update --init --recursive -q -- 2>&1); then
print_error 'Error during git submodule update' ${ERR} print_error 'Error during git submodule update' ${ERR}
return 1 return 1
fi fi

View file

@ -373,7 +373,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2021-11-11 03:49:14 UTC, previous commit is 6e7c6a2)' print -R 'zimfw version: '${_zversion}' (built at 2021-11-11 18:43:25 UTC, previous commit is cd71c8d)'
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)
@ -647,46 +647,45 @@ case \${ACTION} in
fi fi
;; ;;
update) update)
readonly GIT_DIR=\${DIR}/.git if [[ ! -r \${DIR}/.git ]]; then
if [[ ! -d \${GIT_DIR} ]]; 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 -C \${DIR} --git-dir=\${GIT_DIR} config --get remote.origin.url) ]]; then if [[ \${URL} != \$(command git -C \${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 -C \${DIR} --git-dir=\${GIT_DIR} fetch -pq origin 2>&1); then if ! ERR=\$(command git -C \${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 -C \${DIR} --git-dir=\${GIT_DIR} describe --tags --exact-match 2>/dev/null) ]]; then if [[ \${REV} == \$(command git -C \${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 -C \${DIR} --git-dir=\${GIT_DIR} remote set-head origin -a 2>&1); then if ! ERR=\$(command git -C \${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 -C \${DIR} --git-dir=\${GIT_DIR} symbolic-ref --short refs/remotes/origin/HEAD)#origin/} || return 1 REV=\${\$(command git -C \${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 -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) LOG=\$(command git -C \${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 if ! ERR=\$(command git -C \${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 -C \${DIR} --git-dir=\${GIT_DIR} merge --ff-only --no-progress -n 2>&1); then if ! OUT=\$(command git -C \${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
@ -696,7 +695,7 @@ case \${ACTION} in
OUT=\"Updating to \${TYPE} \${REV}\" OUT=\"Updating to \${TYPE} \${REV}\"
fi fi
if [[ -n \${SUBMODULES} ]]; then if [[ -n \${SUBMODULES} ]]; then
if ! ERR=\$(command git -C \${DIR} --git-dir=\${GIT_DIR} submodule update --init --recursive -q -- 2>&1); then if ! ERR=\$(command git -C \${DIR} submodule update --init --recursive -q -- 2>&1); then
print_error 'Error during git submodule update' \${ERR} print_error 'Error during git submodule update' \${ERR}
return 1 return 1
fi fi