#!/bin/sh set -e ## # variables libexec=$(dirname "$0") localbase=${LOCALBASE:-/usr/local} git="${localbase}"/bin/git gitdir=$1 branch=$2 mode="u=rwX,g=rX,o=" ## # functions gitexec() { doas -n -u _srczap \ /bin/sh -c "umask ${mode}; ${git} ${1}" } change_branch() { set +e remote=$1 branch=$2 echo "[-] Attempt to change branch: ${branch}" gitexec "fetch ${remote} > /dev/null 2>&1" if ! gitexec "checkout ${branch} > /dev/null 2>&1" || gitexec "checkout -t ${remote}/${branch} > /dev/null 2>&1"; then r="${?}" echo "[x] 'git checkout' exited with an error" exit "${r}" else echo "[-] Done" fi set -e } ## # main if ! "${libexec}"/issrczap-member; then echo "[x] This command must be run by a member of the '_srczap' group" exit 1 fi if [ ! -e "${gitdir}/.git" ]; then set +x echo "[x] ${gitdir} is not a valid git repository." echo "[x] Try 'srczap clone'" exit 1 fi cd "${gitdir}" remote=$(gitexec "remote" | head -n1) cbranch=$(gitexec "branch --show-current") if [ "${cbranch}" != "${branch}" ]; then change_branch "${remote}" "${branch}" fi set -x gitexec "pull --rebase ${remote} ${branch}"