Handle 'git checkout' error gracefully

Previous commit was focused on portzap-pull.
This one covers portzap-clone.
This commit is contained in:
0x1eef 2024-04-19 09:54:21 -03:00
parent bfdc145d92
commit 300dd161c2
2 changed files with 13 additions and 6 deletions

View file

@ -8,6 +8,7 @@ git="${localbase}"/bin/git
giturl=$1
gitdir=$2
branch=$3
mode="u=rwX,g=rwX,o="
##
# main
@ -23,11 +24,17 @@ if [ -e "${gitdir}/.git" ]; then
fi
set -x
umask u=rwX,g=rwX,o=
umask "${mode}"
doas -u _portzap "${git}" clone "${giturl}" "${gitdir}"
cd "${gitdir}"
doas -u _portzap "${git}" config core.filemode off
set +x +e
echo "[-] Checkout ${branch}"
doas -u _portzap "${git}" checkout -t origin/"${branch}" > /dev/null 2>&1;
echo "[-] Done"
echo "[-] git checkout ${branch}"
if ! doas -u _portzap "${git}" \
checkout -t \
origin/"${branch}" \
> /dev/null 2>&1; then
echo "[-] 'git checkout' exited with an error"
exit "${?}"
else
echo "[-] Done"
fi

View file

@ -22,7 +22,7 @@ change_branch()
if ! doas -u _portzap "${git}" checkout "${branch}" > /dev/null 2>&1 ||
doas -u _portzap "${git}" checkout -t "${remote}"/"${branch}" > /dev/null 2>&1; then
echo "[-] 'git checkout' exited with an error"
exit 1
exit "${?}"
else
echo "[-] Done"
fi