2024-05-11 21:43:59 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
2024-05-11 21:03:00 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
# 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="${?}"
|
2024-05-11 23:52:45 +02:00
|
|
|
echo "[x] 'git checkout' exited with an error"
|
2024-05-11 21:03:00 +02:00
|
|
|
exit "${r}"
|
|
|
|
else
|
|
|
|
echo "[-] Done"
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
##
|
|
|
|
# main
|
|
|
|
if ! "${libexec}"/issrczap-member; then
|
2024-05-11 23:52:45 +02:00
|
|
|
echo "[x] This command must be run by a member of the '_srczap' group"
|
2024-05-11 21:03:00 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "${gitdir}/.git" ]; then
|
|
|
|
set +x
|
2024-05-11 23:52:45 +02:00
|
|
|
echo "[x] ${gitdir} is not a valid git repository."
|
|
|
|
echo "[x] Try 'srczap clone'"
|
2024-05-11 21:03:00 +02:00
|
|
|
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}"
|