scripts

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

gogithub (1700B)


      1 #!/bin/sh
      2 
      3 #when forking a repo from github, one might need to mask imports in a package
      4 #this scripts checks for the existence of a local package with the same name
      5 #and links/unlinks the remote into the local. 
      6 #so let's say that you fork on github https://github.com/foo/bar and you are baz.
      7 #you would git clone git@github.com:baz/bar.git but it would contain all the upstream imports
      8 #using this scipt you will be able to fool your go installation to point them to your local copy.
      9 #by doing: gogithub mask foo/bar 
     10 #and restoring it by: gogithub unmask foo/bar
     11 
     12 checkexistence() {
     13 	localpkg=${1#*/}
     14 	if [ -L "$GOPATH/src/github.com/$1" ] && [ -e "$GOPATH/src/$localpkg" ]; then
     15 		echo "link found. already masked"
     16 	elif ! [ -e "$GOPATH/src/github.com/$1" ] || ! [ -e "$GOPATH/src/$localpkg" ]; then
     17 		echo "package with the same name not found under $GOPATH/src/github.com and $GOPATH/src"
     18 		exit 1
     19 	fi
     20 }
     21 
     22 mask() {
     23 	echo "masking" $1
     24 	localpkg=${1#*/}
     25 	checkexistence $1
     26 	if [ -e "$GOPATH/src/github.com/$1-upstream" ]; then
     27 		echo "package has been already masked. resolve manually"
     28 		exit 1
     29 	fi
     30 	mv $GOPATH/src/github.com/$1 $GOPATH/src/github.com/$1-upstream
     31 	ln -s $GOPATH/src/$localpkg $GOPATH/src/github.com/$1
     32 	exit 0
     33 }
     34 
     35 unmask() {
     36 	echo "unmasking" $1
     37 	checkexistence $1
     38 	if ! [ -e "$GOPATH/src/github.com/$1-upstream" ]; then
     39 		echo "package has been not been masked."
     40 		exit 1
     41 	fi
     42 	rm $GOPATH/src/github.com/$1
     43 	mv $GOPATH/src/github.com/$1-upstream $GOPATH/src/github.com/$1
     44 	exit 0
     45 }
     46 
     47 usage() {
     48 	echo $0 " [mask|unmask] pkgname"
     49 	exit 1
     50 }
     51 
     52 if [ ${#} -eq 0 ] || [ ${#} -gt 2 ]; then 
     53 	usage
     54 elif [ $1 = "mask" ]; then
     55 	mask $2
     56 elif [ $1 = "unmask" ]; then
     57 	unmask $2
     58 else
     59 	usage
     60 fi
     61