Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 89 lines (72 sloc) 2.74 KB
#!/bin/bash
#
# The hook should exit with non-zero status after issuing
# an appropriate message if it wants to stop the commit.
# Strictly disallow uninitialized Variables
set -u
# Exit if a single command breaks and its failure is not handled accordingly
set -e
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# If there are whitespace errors, print the offending file names and fail.
git diff-index --check --cached $against -- 1>&2 || echo -e "\033[0;31mThis commit contains whitespace issues!\033[0m"
# Usefull hooks for the Arch User Repository or Arch Build System
# Fix environment of githooks
unset GIT_DIR
# Allow to read user input below, assigns stdin to keyboard
exec < /dev/tty
# Iterate through folders with a PKGBUILD
# shellcheck disable=SC2046
for path in $(dirname $(git diff --name-only --cached) 2>/dev/null | sort -u); do
if [[ -f "${path}/PKGBUILD" ]]; then
echo -e "\033[1;32m==>\e[39;1m Entering ${path}...\e[0m"
# Ask whether updating the checksums is desired
updpkgsums_cmd="updpkgsums"
echo -en "\e[34;1m ->\e[39;1m Do you want to update the checksums using '${updpkgsums_cmd}'? [Y/n] \e[0m"
read -rn1 user_input
echo
if [[ ${user_input} =~ (Y|y) ]]; then
(cd "${path}" && ${updpkgsums_cmd})
# Update tracked PKGBUILD
git add -u "${path}/PKGBUILD" 1> /dev/null
fi
unset user_input
# Ask whether a rebuild is desired
makepkg_cmd="makepkg -sfc"
echo -en "\e[34;1m ->\e[39;1m Do you want to rebuild the package using '${makepkg_cmd}'? [Y/n] \e[0m"
read -rn1 user_input
echo
if [[ ${user_input} =~ (Y|y) ]]; then
cd "${path}" || exit 1
echo
if ! ${makepkg_cmd}; then
# Ask to abort the commit in case the build fails
echo -en "\n\e[34;1m ->\e[39;1m A failure occured while building the package. Do you want to abort this commit? [Y/n] \e[0m"
read -rn1 user_input_two
echo
if [[ ${user_input_two} =~ (Y|y) ]]; then
exit 2
fi
else
echo
fi
cd - 1>/dev/null
fi
unset user_input
echo -e "\e[34;1m ->\e[39;1m Generating .SRCINFO...\e[0m"
(cd "${path}" && makepkg --printsrcinfo | head -n -1 > .SRCINFO)
echo -e "\e[34;1m ->\e[39;1m Checking PKGBUILD with namcap...\033[0m"
[[ ! -x "/usr/bin/namcap" ]] && echo -e "\e[0;31m ->\e[39;1m Unable to execute /usr/bin/namcap... aborting commit\e[0m" && exit 1
(cd "${path}" && namcap PKGBUILD)
# Add the .SRCINFO file if it is not tracked already
if ! git ls-files "${path}/.SRCINFO" --error-unmatch &> /dev/null; then
git add "${path}/.SRCINFO"
echo -e "\e[34;1m ->\e[39;1m Adding .SRCINFO to git tree...\033[0m"
fi
git add -u "${path}/.SRCINFO" 1>/dev/null
fi
done
You can’t perform that action at this time.