From 300dd161c2953f5b53717628ef9b7fcedde53b86 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 19 Apr 2024 09:54:21 -0300 Subject: [PATCH] Handle 'git checkout' error gracefully Previous commit was focused on portzap-pull. This one covers portzap-clone. --- libexec/portzap/portzap-clone | 17 ++++++++++++----- libexec/portzap/portzap-pull | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libexec/portzap/portzap-clone b/libexec/portzap/portzap-clone index c612ae8..1b384c6 100755 --- a/libexec/portzap/portzap-clone +++ b/libexec/portzap/portzap-clone @@ -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 diff --git a/libexec/portzap/portzap-pull b/libexec/portzap/portzap-pull index 45395f1..0e8b1bb 100755 --- a/libexec/portzap/portzap-pull +++ b/libexec/portzap/portzap-pull @@ -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