Created
January 9, 2017 22:56
-
-
Save chuckg/a97ad7af228c53f05f1f9c378073afe2 to your computer and use it in GitHub Desktop.
golang tools
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
go_clone_usage() { | |
echo | |
echo 'HEY DUMBO ... the following variables must be exported:' | |
echo | |
echo " - \$REPO_UPSTREAM" | |
echo " - \$REPO_FORK" | |
echo | |
echo 'Usage:' | |
echo | |
echo " REPO_UPSTREAM=github.com/klarna/eremetic" | |
echo " REPO_FORK=github.com/chuckg/eremetic" | |
echo " go_clone" | |
} | |
go_clone() { | |
if [ -z "$REPO_UPSTREAM" ]; then | |
go_clone_usage | |
elif [ -z "$REPO_FORK" ]; then | |
go_clone_usage | |
else | |
echo "Cloning $REPO_UPSTREAM ..." | |
go get $REPO_UPSTREAM | |
echo | |
echo "Changing current working directory to $GOPATH/src/$REPO_UPSTREAM ..." | |
cd $GOPATH/src/$REPO_UPSTREAM | |
# Switch the remotes around | |
echo "Renaming remote 'origin' to 'upstream' for $REPO_UPSTREAM ..." | |
git remote rename origin upstream | |
echo | |
echo "Adding new origin remote to $REPO_FORK ..." | |
git remote add origin git@$(echo $REPO_FORK | sed 's/\//:/').git | |
echo | |
echo "Fetching remotes ..." | |
git fetch upstream | |
git fetch origin | |
echo | |
# Remove upstream/master and replace with origin/master on master. | |
echo "Removing upstream/master and replacing with new origin/master ..." | |
git checkout origin/master | |
git branch -d master | |
git co -b master origin/master | |
echo | |
echo "Done cloning $REPO_UPSTREAM" | |
echo | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment