Oliver Schmid

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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 log of 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.
  • Enter will 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!


Comments are not available yet but feel free to reach out to me through the Contact page. - Oliver