Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hooks and PS1 for Go. #5

Merged
merged 1 commit into from
Jul 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
27 changes: 27 additions & 0 deletions misc/git/hooks/gofmt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions misc/git/pre-commit
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions misc/git/ps1
Original file line number Diff line number Diff line change
@@ -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\]\$ '