diff --git a/bootstrap.sh b/bootstrap.sh index 09306c5071f..a74c9ab7990 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -115,5 +115,7 @@ else python ./setup.py install --prefix=$cbson_dist fi - +# create pre-commit hooks +echo "creating git pre-commit hooks" +ln -sf $VTTOP/misc/git/pre-commit $VTTOP/.git/hooks/pre-commit echo "source dev.env in your shell to complete the setup." diff --git a/misc/git/hooks/gofmt b/misc/git/hooks/gofmt new file mode 100755 index 00000000000..6d7a803a4a0 --- /dev/null +++ b/misc/git/hooks/gofmt @@ -0,0 +1,27 @@ +#!/bin/sh +# Copyright 2012 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# git gofmt pre-commit hook +# +# To use, store as .git/hooks/pre-commit inside your repository and make sure +# it has execute permissions. +# +# This script does not handle file names that contain spaces. +gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') + +[ -z "$gofiles" ] && exit 0 +unformatted=$(gofmt -l=true $gofiles 2>&1 | awk -F: '{print $1}') +[ -z "$unformatted" ] && exit 0 + +# Some files are not gofmt'd. Print message and fail. + +echo >&2 "Go files must be formatted with gofmt. Please run:" +echo -n >&2 " gofmt -w" +for fn in $unformatted; do + echo -n >&2 " $PWD/$fn" +done +echo + +exit 1 \ No newline at end of file diff --git a/misc/git/pre-commit b/misc/git/pre-commit new file mode 100755 index 00000000000..61ea2edbf6a --- /dev/null +++ b/misc/git/pre-commit @@ -0,0 +1,12 @@ +#!/bin/bash + +# Runs any hooks in mic/git/hooks, and exits if any of them fail. +set -e + +# This is necessary because the Emacs extensions don't set GIT_DIR. +if [ -z "$GIT_DIR"]; then + GIT_DIR="$(pwd)/.git" +fi +for hook in $GIT_DIR/../misc/git/hooks/*; do + $hook +done \ No newline at end of file diff --git a/misc/git/ps1 b/misc/git/ps1 new file mode 100644 index 00000000000..2ef136f8fc5 --- /dev/null +++ b/misc/git/ps1 @@ -0,0 +1,12 @@ +# Source this file in your shell to get the current git branch name in +# the prompt. + +# parse_git_branch echoes the name of the current branch followed by a +# space (if its not nil). +function parse_git_branch { + branch=$(git branch --no-color 2> /dev/null |grep '*'|awk '{print $2}') + if [ ! -z $branch ]; then + echo " $branch" + fi +} +PS1='\A [\j] (\u \[\e[1;34m\]\h\[\e[m\]):\w\[\e[0;31m\]$(parse_git_branch)\[\e[m\]\$ ' \ No newline at end of file