From e8a4f6d2b59a06cc7054860c6ae9526fecbcdcf8 Mon Sep 17 00:00:00 2001 From: Dom Chen Date: Tue, 5 Nov 2024 09:37:38 +0800 Subject: [PATCH] Fix update_baseline.sh to restore the original branch after updating the baseline. (#2565) --- autotest.sh | 5 ++--- test/src/utils/Baseline.cpp | 5 ++--- update_baseline.sh | 7 ++++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/autotest.sh b/autotest.sh index 675ca47812..d9f42c33c0 100755 --- a/autotest.sh +++ b/autotest.sh @@ -15,15 +15,14 @@ WORKSPACE=$(pwd) cd $WORKSPACE -make_dir result -make_dir build - ./update_baseline.sh 1 if test $? -ne 0; then exit 1 fi cp -r $WORKSPACE/test/baseline $WORKSPACE/result +make_dir result +make_dir build cd build cmake -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -g -O0" -DPAG_USE_SWIFTSHADER=ON -DPAG_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ../ diff --git a/test/src/utils/Baseline.cpp b/test/src/utils/Baseline.cpp index faa4024401..873bd0ca6b 100644 --- a/test/src/utils/Baseline.cpp +++ b/test/src/utils/Baseline.cpp @@ -212,9 +212,8 @@ void Baseline::saveData() { outMD5File << std::setw(4) << outputMD5 << std::endl; outMD5File.close(); CreateFolder(cacheVersionPath); - std::ofstream outVersionFile(cacheVersionPath); - outVersionFile << std::setw(4) << baselineVersions << std::endl; - outVersionFile.close(); + std::filesystem::copy(baselineVersionPath, cacheVersionPath, + std::filesystem::copy_options::overwrite_existing); } #else std::filesystem::remove(outMD5Path); diff --git a/update_baseline.sh b/update_baseline.sh index ec93f602d7..6c0565c375 100755 --- a/update_baseline.sh +++ b/update_baseline.sh @@ -9,6 +9,7 @@ fi echo "~~~~~~~~~~~~~~~~~~~Update Baseline Start~~~~~~~~~~~~~~~~~~~~~" CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + CURRENT_COMMIT=$(git rev-parse HEAD) STASH_LIST_BEFORE=$(git stash list) git stash push --quiet STASH_LIST_AFTER=$(git stash list) @@ -59,7 +60,11 @@ cd .. - git switch $CURRENT_BRANCH --quiet + if [[ $CURRENT_BRANCH == "HEAD" ]]; then + git checkout $CURRENT_COMMIT --quiet + else + git switch $CURRENT_BRANCH --quiet + fi if [[ $STASH_LIST_BEFORE != "$STASH_LIST_AFTER" ]]; then git stash pop --index --quiet fi