Skip to content

Instantly share code, notes, and snippets.

@josephbuchma
Last active December 5, 2016 13:26
Show Gist options
  • Save josephbuchma/b7a8a876da018f12505eab72a17c1dc1 to your computer and use it in GitHub Desktop.
Save josephbuchma/b7a8a876da018f12505eab72a17c1dc1 to your computer and use it in GitHub Desktop.
Simple vendoring helper for Golang.
# 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