Last week I made two commits that broke really obvious things. I was rushing and thought to myself “This is a simple change. Let’s just check it in.” I should have realized that these are every developer’s famous last words…
After these two incidents happened so close to each other, I knew I needed a way to remind myself to be more careful. To sanity check my changes for things the Continuous Integration build might miss.
Checklist for Pushing Code
- Rebase, build, and run tests (it’s quicker to run these locally rather than wait for CI build to fail)
- Sanity test changes
- Check that the app still starts
- Do a basic manual end-to-end sanity test to show your changes work
- Check the functionality around your change still works.
- Review the list of files in each commit (
git log --stat)- Are all necessary files included?
- Are any files included that shouldn't be?
- Read through the diff(s)
- Are there any unfinished sections?
- Are there any sections that you meant to refactor?
- Is each change in a commit related? (e.g. separate incidental code cleanups from feature/bug changes for clarity.)
- Do you want to reword the change description? (Remember it should have an imperative header, and a body describing what and why)
- Update relevant documentation
Inspired by Victoria
Drake I turned this list into a git
hook. Copy the following shell script into .git/hooks and name it pre-push.
#!/bin/sh
git log origin..HEAD
# Read user input, assign stdin to keyboard
exec < /dev/tty
D="\e[37m" # default
H="\e[39m" # highlight
S="\e[33m" #section
CL=$(cat <<-EOM
${S}Checklist${D}
1 Rebase, build, and unit test
2 App still ${H}starts${D}?
3 ${H}Sanity$D test change
4 Functionality ${H}around$D your change still works?
5 Commit includes ${H}all/only$D necessary files?
6 Review ${H}diffs$D for TODOs and refactors?
7 Is each change in a commit ${H}related${D}?
8 ${H}Clearest$D possible commit messages?
9 Update ${H}docs${D}?
${S}Continue with push? (Y/n):$D
EOM
)
echo "$CL"
while read yn; do
case $yn in
Y|y|"") break;;
N|n) exit 1;;
*) echo "Please answer y (yes) or n (no):" && continue;
esac
done
exec <&-
Some notable features:
- First it prints the
git logof the commits to be pushed. - The most meaningful word in each check is highlighted to make the list quicker to read.
- It only asks once whether to continue with the push, rather than after each check.
Enterwill default to yes.
That’s it! Let me know if you have a similar checklist process. Especially if it has something you think it has something I should add to mine!