scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 44f0defb232ef82e60e6d72d3696dbb25054b615
parent b89c0ccf95f120c45271c83f3159dfe37e82ed15
Author: dsp <dsp@2f30.org>
Date:   Wed, 15 Apr 2015 04:34:37 -0600

initial import of gogithub.

gogithub tries to mask and unmask packages that are imported as remote
in a forked github project to their local counterparts

Diffstat:
Agogithub | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+), 0 deletions(-)

diff --git a/gogithub b/gogithub @@ -0,0 +1,58 @@ +#!/bin/sh + +#when forking a repo from github, one might need to mask imports in a package +#this scripts checks for the existence of a local package with the same name +#and links/unlinks the remote into the local. +#so let's say that you fork on github https://github.com/foo/bar and you are baz. +#you would git clone git@github.com:baz/bar.git but it would contain all the upstream imports +#using this scipt you will be able to fool your go installation to point them to your local copy. +#by doing: gogithub mask foo/bar +#and restoring it by: gogithub unmask foo/bar + +checkexistence() { + localpkg=${1#*/} + if ! [ -e "$GOPATH/src/github.com/$1" ] || ! [ -e "$GOPATH/src/$localpkg" ]; then + echo "package with the same name not found under $GOPATH/src/github.com and $GOPATH/src" + exit 1 + fi +} + +mask() { + echo "masking" $1 + checkexistence $1 + if [ -e "$GOPATH/src/github.com/$1-upstream" ]; then + echo "package has been already masked. resolve manually" + exit 1 + fi + mv $GOPATH/src/github.com/$1 $GOPATH/src/github.com/$1-upstream + ln -s $GOPATH/src/localpkg $GOPATH/src/github.com/$1 + exit 0 +} + +unmask() { + echo "unmasking" $1 + checkexistence $1 + if ! [ -e "$GOPATH/src/github.com/$1-upstream" ]; then + echo "package has been not been masked." + exit 1 + fi + unlink $GOPATH/src/github.com/$1 + mv $GOPATH/src/github.com/$1-upstream $GOPATH/src/github.com/$1 + exit 0 +} + +usage() { + echo $0 " [mask|unmask] pkgname" + exit 1 +} + +if [ ${#} -eq 0 ] || [ ${#} -gt 2 ]; then + usage +elif [ $1 = "mask" ]; then + mask $2 +elif [ $1 = "unmask" ]; then + unmask $2 +else + usage +fi +