Last active
December 5, 2016 13:26
-
-
Save josephbuchma/b7a8a876da018f12505eab72a17c1dc1 to your computer and use it in GitHub Desktop.
Simple vendoring helper for Golang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vget is a simiple vendoring helper for golang. | |
# Example: | |
# vget.sh https://github.com/lib/pq dev | |
# will clone repository to ./vendor/github.com/lib/pq, check out `dev` and remove .git directory. | |
[ $# -eq 0 ] && echo 'Usage:\n\t vget <git_repo_clone_url> [git_ref]' | |
a=$1 | |
p=vendor/${a:8} | |
if [ ! -d $p ] || [ ! -d "$p/.git" ]; then | |
echo 'Clone...' | |
rm -rf $p > /dev/null 2>&1 | |
git clone $a $p > /dev/null 2>&1 | |
fi | |
_pwd=`pwd` | |
if [ $# -eq 2 ]; then | |
echo "Check out $2" | |
cd $p && git checkout $2 > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "git checkout FAILED. Rerun vget with correct git ref or go to $p, checkout manually and delete .git" | |
cd $_pwd | |
return 1 | |
fi | |
fi | |
cd $_pwd | |
echo 'Remove .git' | |
rm -rf "$p/.git" | |
echo 'Done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment