sourcezap/libexec/srczap/srczap-pull
0x1eef ea06f0dfbc First commit
A modified copy of portzap repurposed for management of the
hardenedbsd source tree.
2024-05-11 16:03:00 -03:00

59 lines
1.2 KiB
Bash
Executable file

#!/bin/sh -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 "[-] 'git checkout' exited with an error"
exit "${r}"
else
echo "[-] Done"
fi
set -e
}
##
# main
if ! "${libexec}"/issrczap-member; then
echo "[-] This command must be run by a member of the '_srczap' group"
exit 1
fi
if [ ! -e "${gitdir}/.git" ]; then
set +x
echo "[-] ${gitdir} is not a valid git repository."
echo "[-] 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}"