How can I get git push to ask for confirmation or run some checks? -
i customize git prompt in such way reminds me or runs checks me before push remote repo.
for instance, when run
git push git should ask user
did run unit tests locally? or effect, don't accidentally push code not unit-tested.
set pre-push hook prevent pushing unless file .testspassed exists. example:
cat > .git/hooks/pre-push <<eof #!/bin/sh -e if ! [ -f .testspassed ]; echo 1>&2 "push aborted because tests not run or did not pass" exit 1 fi exit 0 eof chmod +x .git/hooks/pre-push set prepare-commit-msg hook remove .testspassed if exists:
cat > .git/hooks/prepare-commit-msg <<eof #!/bin/sh -e rm -f .testspassed exit 0 eof i'm using prepare-commit-msg instead of pre-commit because prepare-commit-msg runs on merges too. time commit or merge, git remove .testspassed file, preventing pushing.
tell git ignore .testspassed file doesn't end in repo:
echo .testspassed >> .gitignore git commit -m 'add .testspassed .gitignore' .gitignore finally, modify test-run process create (“touch”) .testspassed if tests pass. how depends on how run tests.
Comments
Post a Comment