Skip to content

Commit b293a4d

Browse files
redsun82Copilot
andcommitted
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>
1 parent 27f8d95 commit b293a4d

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/test

rust/ql/lib/upgrades/66a489863649185f4a9770f894505803059a1312/test/run-test.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ trap 'rm -rf "$OLD_TEST_TMP"' EXIT
1818
cp "$SCRIPT_DIR/old/OldShapes.ql" "$SCRIPT_DIR/old/OldShapes.expected" "$OLD_TEST_TMP/"
1919
cp "$SCRIPT_DIR/new/qlpack.yml" "$SCRIPT_DIR/new/upgrade_shapes.rs" "$OLD_TEST_TMP/"
2020

21-
echo "==> Stashing any uncommitted changes..."
22-
git stash --quiet || true
21+
# Stash changes only if there are any (including untracked files)
22+
STASH_REF=""
23+
if ! git diff --quiet HEAD || [ -n "$(git ls-files --others --exclude-standard)" ]; then
24+
echo "==> Stashing uncommitted changes..."
25+
STASH_REF=$(git stash create --include-untracked)
26+
if [ -n "$STASH_REF" ]; then
27+
git stash store -m "run-test.sh auto-stash" "$STASH_REF"
28+
fi
29+
fi
2330

2431
restore_branch() {
2532
echo "==> Restoring original branch..."
2633
git checkout --quiet -
27-
git stash pop --quiet 2>/dev/null || true
34+
if [ -n "$STASH_REF" ]; then
35+
git stash pop --quiet
36+
fi
2837
}
2938
trap 'restore_branch; rm -rf "$OLD_TEST_TMP"' EXIT
3039

0 commit comments

Comments
 (0)