File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,38 @@ ROOT_DIR="$(git rev-parse --show-toplevel)"
2626echo " Running pre-push script $ROOT_DIR /x test tidy"
2727
2828cd " $ROOT_DIR "
29+
30+ # Check if the local working dir contains uncommitted changes (including untracked files).
31+ if [ -n " $( git status --porcelain) " ]; then
32+ echo " Stashing local uncommitted changes before running Tidy."
33+ # Stash uncommitted changes so that tidy only checks what you are going to push.
34+ git stash push -u -q
35+ if [ $? -ne 0 ]; then
36+ echo " Error: Failed to stash changes."
37+ echo " You may use \` git push --no-verify\` to skip this pre-push check."
38+ exit 1
39+ fi
40+ STASHED=true
41+ else
42+ STASHED=false
43+ fi
44+
2945./x test tidy --set build.locked-deps=true
30- if [ $? -ne 0 ]; then
46+ TIDY_RESULT=$?
47+
48+ # Only pop the stash if something was previously stashed during this check.
49+ if [ " $STASHED " = true ]; then
50+ echo " Restoring stashed changes."
51+ # Split the stash pop into `apply` and `drop` so a user can fix things if this fails.
52+ if ! git stash apply -q; then
53+ echo " Warning: Failed to apply stashed changes due to conflicts."
54+ echo " Please resolve the conflicts manually and then run 'git stash drop' when finished."
55+ else
56+ git stash drop -q
57+ fi
58+ fi
59+
60+ if [ $TIDY_RESULT -ne 0 ]; then
3161 echo " You may use \` git push --no-verify\` to skip this check."
3262 exit 1
3363fi
You can’t perform that action at this time.
0 commit comments