diff --git a/misc/pre-commit.githook b/misc/pre-commit.githook index f9fd2d36b..c0fe8f0f4 100755 --- a/misc/pre-commit.githook +++ b/misc/pre-commit.githook @@ -1,6 +1,22 @@ #!/usr/bin/env sh exitstatus=0 + +#third_party imports. +cd third_party +rewrite=`./rewrite-imports.sh -l` +cd .. +if [ -n "$rewrite" ] +then + exitstatus=1 + for r in $rewrite + do + echo $r + done + echo "The above need their imports to be fixed. Use rewrite-imports.sh -w" +fi + +#gofmt and trailing space errors committed=`git diff-index --cached --name-only HEAD` for c in $committed do diff --git a/third_party/rewrite-imports.sh b/third_party/rewrite-imports.sh index 4cd6d2182..e2d0d93fb 100755 --- a/third_party/rewrite-imports.sh +++ b/third_party/rewrite-imports.sh @@ -1,7 +1,21 @@ #!/bin/sh -find . -type f -name '*.go' -exec perl -pi -e 's!"code.google.com/!"camlistore.org/third_party/code.google.com/!' {} \; -find . -type f -name '*.go' -exec perl -pi -e 's!"launchpad.net/!"camlistore.org/third_party/launchpad.net/!' {} \; -find . -type f -name '*.go' -exec perl -pi -e 's!"github.com/!"camlistore.org/third_party/github.com/!' {} \; -find . -type f -name '*.go' -exec perl -pi -e 's!"labix.org/!"camlistore.org/third_party/labix.org/!' {} \; - +if [ "$1" = "-l" ] +then + find . -type f -name '*.go' -exec grep -E -l '"code.google.com/' {} \; + find . -type f -name '*.go' -exec grep -E -l '"launchpad.net/' {} \; + find . -type f -name '*.go' -exec grep -E -l '"github.com/' {} \; + find . -type f -name '*.go' -exec grep -E -l '"labix.org/' {} \; +elif [ "$1" = "-w" ] +then + find . -type f -name '*.go' -exec perl -pi -e 's!"code.google.com/!"camlistore.org/third_party/code.google.com/!' {} \; + find . -type f -name '*.go' -exec perl -pi -e 's!"launchpad.net/!"camlistore.org/third_party/launchpad.net/!' {} \; + find . -type f -name '*.go' -exec perl -pi -e 's!"github.com/!"camlistore.org/third_party/github.com/!' {} \; + find . -type f -name '*.go' -exec perl -pi -e 's!"labix.org/!"camlistore.org/third_party/labix.org/!' {} \; +else + cat << heredoc +usage: rewrite-imports.sh -l|-w" + -l: list files where a rewrite is needed" + -w: actually performs the rewrite" +heredoc +fi