neverpanic.de

whatthecommit.com Git Hook

| Comments

whatthecommit.com generates commit messages for the lazy… but being one of the laziest people, this isn’t just easy enough!

I currently use Git for most of my version control needs. I’m keeping all of my hand-ins for university under version control to be able to sync them between university and my laptop easily and to make it easy for others to contribute (and sometimes they actually do!). But those of you using version control systems know what the biggest problem with version control is: Thinking of a commit message. Wait no moar! The ultimate solution is here!

whatthecommit.com is a website that provides you with a fresh commit message every time you load it. So all you have to do, is copy and paste the line into your commit window. Still too much work? That’s why git comes with hook scripts. Paste the following code in .git/hooks/prepare-commit-msg in your working copy and make the file executable and you’ll be provided with a wonderful commit message every time you type git commit automatically!

whatthecommit.com git hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# A hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source.  The hook's purpose is to edit the commit
# message file.  If the hook fails with a non-zero status,
# the commit is aborted.

case "$2,$3" in
  ,|template,)
      line=$( curl -L http://whatthecommit.com/ 2>/dev/null | grep -Po '(?<=\<p\>).*$' )
      file=$( sed '1d' "${1}" )
      echo "${line}" > "${1}"
      echo "${file}" >> "${1}"
  ;;
  *) ;;
esac

Comments