branch() {
case "$@" in
"branch --show-current")
if [ -f .git/branch ]; then
echo $(< .git/branch)
else
echo "main"
fi
;;
esac
}
commit() {
if [ -f .git/error ]; then
echo "fake error"
exit $(< .git/error)
fi
if [[ "$@" != *"--no-verify"* ]]; then
if [ -x .git/hooks/pre-commit ]; then
.git/hooks/pre-commit
if [ $? -ne 0 ]; then
exit 1
fi
fi
if [ -x .git/hooks/commit-msg ]; then
.git/hooks/commit-msg
if [ $? -ne 0 ]; then
exit 1
fi
fi
fi
echo "fake commit"
echo -n "$@" > .git/commit
}
rev_parse() {
case "$@" in
"rev-parse --show-toplevel")
pwd
;;
"rev-parse --git-dir")
echo "$(pwd)/.git"
;;
"rev-parse --is-inside-work-tree")
if [ ! -d .git ]; then
return 1
elif [ -f .git/bare ]; then
echo "false"
else
echo "true"
fi
;;
esac
}
case $1 in
branch)
branch "$@"
;;
commit)
commit "$@"
;;
rev-parse)
rev_parse "$@"
;;
esac