From 76047ad883d4609a8d7c5b2b792008408c91abcd Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 27 May 2026 08:13:04 +0200 Subject: [PATCH] Fix unsafe stash handling in run-test.sh Only stash when there are actual changes (including untracked files), and only pop the specific stash entry we created. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../test/run-test.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/test/run-test.sh b/rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/test/run-test.sh index a4e8e9f53a8..a3f65d9897c 100755 --- a/rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/test/run-test.sh +++ b/rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/test/run-test.sh @@ -18,13 +18,22 @@ trap 'rm -rf "$OLD_TEST_TMP"' EXIT cp "$SCRIPT_DIR/old/OldShapes.ql" "$SCRIPT_DIR/old/OldShapes.expected" "$OLD_TEST_TMP/" cp "$SCRIPT_DIR/new/qlpack.yml" "$SCRIPT_DIR/new/upgrade_shapes.rs" "$OLD_TEST_TMP/" -echo "==> Stashing any uncommitted changes..." -git stash --quiet || true +# Stash changes only if there are any (including untracked files) +STASH_REF="" +if ! git diff --quiet HEAD || [ -n "$(git ls-files --others --exclude-standard)" ]; then + echo "==> Stashing uncommitted changes..." + STASH_REF=$(git stash create --include-untracked) + if [ -n "$STASH_REF" ]; then + git stash store -m "run-test.sh auto-stash" "$STASH_REF" + fi +fi restore_branch() { echo "==> Restoring original branch..." git checkout --quiet - - git stash pop --quiet 2>/dev/null || true + if [ -n "$STASH_REF" ]; then + git stash pop --quiet + fi } trap 'restore_branch; rm -rf "$OLD_TEST_TMP"' EXIT