Handle file mode change when switching branch

This commit is contained in:
0x1eef 2024-04-19 07:07:33 -03:00
parent a4a6253062
commit 589702e7e3
4 changed files with 25 additions and 28 deletions

View file

@ -20,13 +20,14 @@ if [ -e "${gitdir}/.git" ]; then
echo "[-] ${gitdir} exists." echo "[-] ${gitdir} exists."
echo "[-] Try 'portzap pull'" echo "[-] Try 'portzap pull'"
exit 1 exit 1
else
set -x
umask u=rwX,g=rwX,o=
doas -u _portzap "${git}" clone "${giturl}" "${gitdir}"
cd "${gitdir}"
set +x +e
echo "[-] Checkout ${branch}"
doas -u _portzap "${git}" checkout -t origin/"${branch}" > /dev/null 2>&1;
echo "[-] Done"
fi fi
set -x
umask u=rwX,g=rwX,o=
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"

View file

@ -61,6 +61,7 @@ if [ "$(id -u)" != "0" ]; then
echo "[-] This command must be run as root" echo "[-] This command must be run as root"
exit 1 exit 1
fi fi
set -x set -x
umask u=rwX,g=rwX,o= umask u=rwX,g=rwX,o=
cd "${gitdir}" cd "${gitdir}"

View file

@ -10,13 +10,6 @@ branch=$2
## ##
# functions # functions
set_repository_permissions()
{
gitdir=$1
doas -u root /bin/chmod -R u=rwX,g=rwX,o= "${gitdir}/.git"
doas -u root /usr/sbin/chown -R _portzap:_portzap "${gitdir}/.git"
}
change_branch() change_branch()
{ {
set +e set +e
@ -26,7 +19,6 @@ change_branch()
doas -u _portzap "${git}" fetch "${remote}" > /dev/null 2>&1 doas -u _portzap "${git}" fetch "${remote}" > /dev/null 2>&1
doas -u _portzap "${git}" checkout "${branch}" > /dev/null 2>&1 || doas -u _portzap "${git}" checkout "${branch}" > /dev/null 2>&1 ||
doas -u _portzap "${git}" checkout -t "${remote}"/"${branch}" > /dev/null 2>&1 doas -u _portzap "${git}" checkout -t "${remote}"/"${branch}" > /dev/null 2>&1
doas -u _portzap "${git}" reset HEAD --hard > /dev/null 2>&1
echo "[-] Done" echo "[-] Done"
set -e set -e
} }
@ -38,19 +30,21 @@ if ! "${libexec}"/isportzap-member; then
exit 1 exit 1
fi fi
if [ -e "${gitdir}/.git" ]; then if [ ! -e "${gitdir}/.git" ]; then
umask u=rwX,g=rwX,o=
set_repository_permissions "${gitdir}"
cd "${gitdir}"
remote=$("${git}" remote | head -n1)
if [ "$(git branch --show-current)" != "${branch}" ]; then
change_branch "${remote}" "${branch}"
fi
set -x
doas -u _portzap "${git}" pull --rebase "${remote}" "${branch}"
else
set +x set +x
echo "[-] ${gitdir} is not a valid git repository." echo "[-] ${gitdir} is not a valid git repository."
echo "[-] Try 'portzap clone'" echo "[-] Try 'portzap clone'"
exit 1 exit 1
fi fi
umask u=rwX,g=rwX,o=
doas -u root /bin/chmod -R u=rwX,g=rwX,o= "${gitdir}/.git"
doas -u root /usr/sbin/chown -R _portzap:_portzap "${gitdir}/.git"
cd "${gitdir}"
remote=$("${git}" remote | head -n1)
if [ "$(git branch --show-current)" != "${branch}" ]; then
change_branch "${remote}" "${branch}"
doas -u root /bin/chmod -R u=rwX,g=rwX,o= "${gitdir}"
fi
set -x
doas -u _portzap "${git}" pull --rebase "${remote}" "${branch}"

View file

@ -2,5 +2,6 @@
# portzap # portzap
permit nopass root as _portzap cmd /usr/local/bin/git permit nopass root as _portzap cmd /usr/local/bin/git
permit nopass :_portzap as _portzap cmd /usr/local/bin/git permit nopass :_portzap as _portzap cmd /usr/local/bin/git
permit nopass :_portzap as root cmd /bin/chmod args -R u=rwX,g=rwX,o= /home/_portzap/ports
permit nopass :_portzap as root cmd /bin/chmod args -R u=rwX,g=rwX,o= /home/_portzap/ports/.git permit nopass :_portzap as root cmd /bin/chmod args -R u=rwX,g=rwX,o= /home/_portzap/ports/.git
permit nopass :_portzap as root cmd /usr/sbin/chown args -R _portzap:_portzap /home/_portzap/ports/.git permit nopass :_portzap as root cmd /usr/sbin/chown args -R _portzap:_portzap /home/_portzap/ports/.git