Skip to content

Commit

Permalink
Merge pull request #5 from youtube/repo-improvements
Browse files Browse the repository at this point in the history
Add hooks and PS1 for Go.
  • Loading branch information
ryszard committed Jul 20, 2013
2 parents 90bbf8c + 4bf5d66 commit 762493c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,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\]\$ '

0 comments on commit 762493c

Please sign in to comment.