Skip to content

Instantly share code, notes, and snippets.

@fwielstra
Forked from strootman/pre-push
Last active June 20, 2023 06:38
Show Gist options
  • Save fwielstra/d3619eef4b23176c3db6a157179d3918 to your computer and use it in GitHub Desktop.
Save fwielstra/d3619eef4b23176c3db6a157179d3918 to your computer and use it in GitHub Desktop.
A pre-push git hook which runs a gradle test task
#!/bin/sh
# this hook is in SCM so that it can be shared
# to install it, create a symbolic link in the projects .git/hooks folder
#
# i.e. - from the .git/hooks directory, run
# $ ln -s ../../git-hooks/pre-commit.sh pre-commit
#
# to skip the tests, run with the --no-verify argument
# i.e. - $ 'git commit --no-verify'
set -e
# stash any unstaged changes
git stash save "prePush" -q --keep-index
# unstash the unstashed changes (if any) on exit or interrupt
function unstash {
git stash apply stash^{/prePush} -q || true
}
trap unstash EXIT
# run the tests with the gradle wrapper
./gradlew test -q
@rage-shadowman
Copy link

rage-shadowman commented Apr 30, 2019

How does that unstash function work?

When I try to run it, git says that stash^{/prePush} is not a stash reference even though git stash list | grep prePush shows that one exists.

[edit: Nevermind... The reason mine doesn't work is because I'm using git stash pop instead of git stash apply. When I use "apply" it understands the search string.]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment