#!/usr/bin/bash
# does this post commit work?
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# echo "Here: $here"
here="$(realpath "$here")"
if [[ "${here:(-11)}" == "/.git/hooks" ]];then
root="$(realpath "$here/../../")"
else
root="$(realpath "$here/../")"
fi
# echo "Root: $root"
out="$("$root"/test/run_test)"
# echo "Out: $out"
if [[ -f "$root/config/post-commit" ]];then
source "$root/config/post-commit"
fi
if [[ ! $out -eq 1 ]];then
echo ""
echo "Tests failed, not pushing to stable."
echo ""
exit;
fi
if [[ -z "${always_push:-}" && "$always_push" != true ]];then
read -p "Push to stable?" y
if [[ "$y" != "y" ]];then
exit;
fi
fi
dev="$(git branch --show-current)";
stable="${dev%-dev}"
# echo "Dev: $dev"
# echo "Stable: $stable"
if [[ "$dev" == "$stable" ]];then
exit;
fi
# echo 'go'
# exit;
git checkout -B "${stable}"
git pull "${stable}"
# exit
#okay okay
git merge "${dev}"
git commit -am "merge ${dev}"
git push -u origin "${stable}"
git checkout "${dev}"
echo ""
echo ""
echo "Stable Pushed!"
echo ""
# add stufff in -dev branch
# This is where i could ask for a commit for stable, or i could just copy all the commits over (probably not how i should do it)
# And if i get a message, then i will push, merge, commit
# so i check if the branch ends in -dev
# and if it does, then i remove -dev & merge into the non dev branch
# and then i commit