test/diff-manifests: checkout repo to $head on exit

During the diff-manifests.sh test the source repository checkout is
changed to generate manifests from current main branch for comparion. We
want to checkout back to $head after the script is done or in case of
any unexpected exit.
This commit is contained in:
Jakub Rusz 2022-07-26 14:42:45 +02:00 committed by Christian Kellner
parent cf562dbb57
commit 74bf3aa3df

View file

@ -9,6 +9,9 @@ function greenprint {
function redprint {
echo -e "\033[1;31m[$(date -Isecond)] ${1}\033[0m"
}
function revert_to_head {
git checkout "$head"
}
if [[ "${CI_COMMIT_BRANCH}" != PR-* ]]; then
greenprint "${CI_COMMIT_BRANCH} is not a Pull Request"
@ -60,6 +63,8 @@ if (( err != 0 )); then
exit 1
fi
# revert to $head on exit
trap revert_to_head EXIT
greenprint "Checking out merge-base ${mergebase}"
git checkout "${mergebase}"