I am running a shell script from another shell script which is a git-hook pre-push
.
This is the content of .git/hooks/pre-push:
#!/usr/bin/env bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]; then
sh test.sh
if [ $? != 0 ]; then
echo "Error"
exit 1
fi
else
exit 0
fi
This is the content of test.sh:
#!/bin/bash
run_base=1
run_test () {
read -p "enter varname: " varname
echo $varname
}
time {
if [ "$run_base" = "0" ] ; then
echo "skipped"
else
time { run_test ; }
echo "run_test done";
fi
}
If I run pre-push
script directly, then it works fine, but it doesn't work when I execute git push origin master
and pre-push
gets triggered automatically.
read
in test.sh is not being executed when I trigger the pre-push
hook script. Do I need to do anything specific in order to execute read
in test.sh
which is called from pre-push
?