From 74bf3aa3df5dfffd58fbe8085d84b10d20497851 Mon Sep 17 00:00:00 2001 From: Jakub Rusz Date: Tue, 26 Jul 2022 14:42:45 +0200 Subject: [PATCH] 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. --- test/cases/diff-manifests.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/cases/diff-manifests.sh b/test/cases/diff-manifests.sh index 794cd564b..f2f2956ed 100755 --- a/test/cases/diff-manifests.sh +++ b/test/cases/diff-manifests.sh @@ -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}"