Cannot execute catkin_make in githook
I have a pre-push
githook that tries to execute catkin_make
before pushing, to only allow pushes that (at least) can compile. It works by git invoking invoking a bash script and depending on the return code allowing or denying the push "request". The githook is invoked locally: nothing is run on the server. The script looks like this (only the important parts):
#!/bin/bash
# "This hook is called by git push and can be used to prevent a push from taking place.
# If this hook exits with a non-zero status, git push will abort without pushing anything.
# Information about why the push is rejected may be sent to the user by writing to standard error."
# see: https://git-scm.com/docs/githooks
# make the script fail if any line fails, see: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
# go to the project root
# taken from here: https://stackoverflow.com/a/1571525/3753684
repo_root=$( git rev-parse --show-toplevel )
cd $repo_root
# build the project once
# this still prints output *on error*, which is what we want
build_output=$( catkin_make )
build_exit_status=$?
if [ $build_exit_status -eq 0 ];
then # it worked, let git push it
# log success message
echo "build succeeded, pushing is allowed"
# exit successfully
exit 0
else # it failed, prevent git from pushing
# log fail message
echo -e "--------------------\n\n"
echo "Failed to build the project. Not pushing."
# exit non-successfully
exit $build_exit_status
fi
When I execute it in the terminal by hand, everything works just fine. But when git invokes it, this error gets printed out: ".git/hooks/pre-push: line 19: catkin_make: command not found". Line 19 is the one containing build_output=$( catkin_make )
. It strangely works on another machine having pretty much the same setup. We both have ROS Kinetic installed on Ubuntu LTS 16.04 and Kubuntu LTS 16.04.
What am I doing wrong?
I think catkin_make itself cannot be found. I have this in my ~/.bashrc
:
source /opt/ros/kinetic/setup.bash
source /home/felix/sailing/bord-pc/devel/setup.bash
export BORD_PC_WORKSPACE=/home/felix/sailing/bord-pc # this is my workspace
And sourcing it in the script and/or in the subshell in line 19 did not work:
source ~/.bashrc
build_output=$( source ~/.bashrc && catkin_make )