github.com/driusan/dgit@v0.0.0-20221118233547-f39f0c15edbb/go-get-tests.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 4 echo "Running go get tests" 5 6 # Ensure that git is called, not the proxy 7 export GOPROXY="direct" 8 9 #Keep existing state 10 export ORIG_PATH=$PATH 11 export ORIG_GIT=$(which git) 12 13 echo "Adding dgit to the path" 14 go build 15 16 # Ensure that expected "go get" behaviour is 17 # consistent across go versions 18 export GO111MODULE="off" 19 20 mkdir -p bin 21 cp dgit bin/git 22 export PATH=$(pwd)/bin:$PATH 23 24 export DGIT_TRACE=/tmp/go-get-dgit-log.$$.txt 25 26 # Make a new $GOPATH and use it so that newer versions of 27 # git with different default module modes don't get confused. 28 export GOPATH=/tmp/gopath.tst 29 export TEST_PKG=github.com/blang/semver 30 export TEST_GIT_DIR=${GOPATH}/src/${TEST_PKG} 31 mkdir -p $GOPATH 32 cd $GOPATH 33 34 echo "Go get a package inside $GOPATH" 35 go get -x ${TEST_PKG} || (echo "Go get ${TEST_PKG} failed"; exit 1) 36 test -d ${GOPATH}/src/${TEST_PKG} || (echo "ERROR: Go get didn't work"; exit 1) 37 38 test -f $DGIT_TRACE || (echo "ERROR: Dgit wasn't called for the go get test"; exit 1) 39 rm -f $DGIT_TRACE 40 41 echo "Reset the package back one commit from master" 42 $ORIG_GIT -C ${TEST_GIT_DIR} reset HEAD^1 > /dev/null 43 $ORIG_GIT -C ${TEST_GIT_DIR} checkout . > /dev/null 44 commitid=$($ORIG_GIT -C ${TEST_GIT_DIR} log --pretty=format:"%h" HEAD^..HEAD) 45 46 echo "Run go get -u on the package" 47 go get -x -u ${TEST_PKG} || (echo "Go get -u failed"; exit 1) 48 test -f $DGIT_TRACE || (echo "ERROR: Dgit wasn't called for the go get -u test"; exit 1) 49 50 echo "Verify that the branch is now up to date with master" 51 commitid2=$($ORIG_GIT -C ${TEST_GIT_DIR} log --pretty=format:"%h" HEAD^..HEAD) 52 53 echo COMMITS: "$commitid" "$commitid2" 54 if [ "$commitid" == "$commitid2" ] 55 then 56 echo "ERROR: Pull did not pull in the latest changes" 57 exit 1 58 fi 59 60 export PATH=$ORIG_PATH