diff --git a/Makefile b/Makefile index b5aef0f..a7d829d 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ symlinks = \ gemrc \ gitconfig \ gitignore \ + git_templates \ pryrc \ ruby-version \ vimrc \ @@ -100,7 +101,7 @@ ruby = $(HOME)/.rubies/ruby-$(ruby_version) bundler = $(ruby)/bin/bundle cocoapods = $(ruby)/bin/pod -ruby: | $(ruby) $(bundler) $(cocoapods) +ruby: | $(ruby) $(bundler) $(fit-commit) $(ruby): | $(fry) $(HOME)/.ruby-version $(cellar)/ruby-install ruby-install ruby $(ruby_version) @@ -111,8 +112,8 @@ gem = $(ruby)/bin/gem $(bundler): | $(ruby) $(gem) install bundler -$(cocoapods): | $(ruby) - $(gem) install cocoapods +$(fit-commit): | $(ruby) + $(gem) install fit-commit # vim diff --git a/git_templates/hooks/commit-msg b/git_templates/hooks/commit-msg new file mode 100755 index 0000000..69712fd --- /dev/null +++ b/git_templates/hooks/commit-msg @@ -0,0 +1,49 @@ +#!/usr/bin/env sh +# +# This hook will attempt to setup your environment before running checks. + +if which rvm > /dev/null 2>&1 +then cmd="rvm default do ruby" +elif which rbenv > /dev/null 2>&1 +then cmd="rbenv exec ruby" +else cmd="ruby" +fi + +export COMMIT_MESSAGE_PATH=$1 +if [ -z "$COMMIT_MESSAGE_PATH" ]; then + >&2 echo "fit-commit: WARNING: Skipping checks because the Git hook was not passed the" + >&2 echo "fit-commit: commit message file path. This is usually \`.git/COMMIT_EDITMSG\`." + >&2 echo "fit-commit: This hook was called via: $0 $*" + >&2 echo "fit-commit: Please submit a bug report with the project:" + >&2 echo "fit-commit: https://github.com/m1foley/fit-commit/issues" + exit 0 +fi +if [ ! -r "$COMMIT_MESSAGE_PATH" ]; then + >&2 echo "fit-commit: WARNING: Skipping checks because the commit message file cannot be read:" + >&2 echo "fit-commit: $COMMIT_MESSAGE_PATH" + >&2 echo "fit-commit: This hook was called via: $0 $*" + >&2 echo "fit-commit: Please submit a bug report with the project:" + >&2 echo "fit-commit: https://github.com/m1foley/fit-commit/issues" + exit 0 +fi + +export GIT_BRANCH_NAME=`git name-rev --name-only HEAD` +if [ -z "$GIT_BRANCH_NAME" ]; then + >&2 echo "fit-commit: WARNING: Skipping checks because the Git branch cannot be determined." + >&2 echo "fit-commit: Please submit a bug report with the project:" + >&2 echo "fit-commit: https://github.com/m1foley/fit-commit/issues" + exit 0 +fi + +${cmd} -rrubygems -e ' + begin + require "fit_commit" + true + rescue LoadError => e + $stderr.puts <<-MESSAGE +fit-commit: WARNING: Skipping checks because: #{e} +fit-commit: Did you set your Ruby version? +MESSAGE + false + end and FitCommit.run +' < /dev/tty diff --git a/gitconfig b/gitconfig index a56b7d1..9c4e026 100644 --- a/gitconfig +++ b/gitconfig @@ -55,3 +55,5 @@ clean = git-lfs clean %f smudge = git-lfs smudge %f required = true +[init] + templatedir = ~/.git_templates