Oliver Schmid Owl Logo

Pre-Push Checklist

 -  read

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

  1. Rebase, build, and run tests (it’s quicker to run these locally rather than wait for CI build to fail)
  2. Sanity test changes
    1. Check that the app still starts
    2. Do a basic manual end-to-end sanity test to show your changes work
    3. Check the functionality around your change still works.
  3. Review the list of files in each commit (git log --stat)
    1. Are all necessary files included?
    2. Are any files included that shouldn't be?
  4. Read through the diff(s)
    1. Are there any unfinished sections?
    2. Are there any sections that you meant to refactor?
    3. Is each change in a commit related? (e.g. separate incidental code cleanups from feature/bug changes for clarity.)
    4. Do you want to reword the change description? (Remember it should have an imperative header, and a body describing what and why)
  5. 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:

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!