Skip to content

Commit ad4870c

Browse files
CopilotRichDom2185
andcommitted
Fix conditional stash pop in test.sh script
- Capture git stash push output to detect if stash was created - Only run git stash pop if a stash was actually created - Prevents popping unrelated stashes when no changes exist - Maintains same output formatting and user experience Co-authored-by: RichDom2185 <[email protected]>
1 parent 7b48206 commit ad4870c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

scripts/test.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
export CI=true
44

55
main() {
6-
run_cmd "git stash push --keep-index --message precommit"
7-
echo " If you cancel this pre-push hook, use \`git stash pop\` to retrieve your"
8-
echo " unstaged changes."
6+
stash_output=$(git stash push --keep-index --message precommit 2>&1)
7+
echo_cyan "> git stash push --keep-index --message precommit"
8+
if [[ ! -z "${stash_output}" ]]; then
9+
echo "${stash_output}" | sed 's/^/ /'
10+
fi
11+
12+
# Check if a stash was actually created
13+
stash_created=false
14+
if [[ "${stash_output}" == *"Saved working directory"* ]]; then
15+
stash_created=true
16+
echo " If you cancel this pre-push hook, use \`git stash pop\` to retrieve your"
17+
echo " unstaged changes."
18+
fi
919

1020
tsc="yarn run tsc"
1121
eslint="yarn run eslint"
@@ -19,7 +29,10 @@ main() {
1929
run_cmd "${prettier_scss}"; prettier_scss_exit=$?
2030
run_cmd_jest "${jest_ts}"; jest_ts_exit=$?
2131

22-
run_cmd "git stash pop"
32+
# Only pop the stash if we actually created one
33+
if [[ "${stash_created}" == true ]]; then
34+
run_cmd "git stash pop"
35+
fi
2336

2437
( >&2
2538
echo -ne "\033[0;31m"

0 commit comments

Comments
 (0)