From d770386404c9885700ff0990be9ed690eb4fd496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 29 Sep 2015 11:38:35 +0300 Subject: [PATCH] Support branch/remote switching with non repo-root packages. --- docker/base/build.sh | 48 ++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/docker/base/build.sh b/docker/base/build.sh index dd39f24..d5bd038 100644 --- a/docker/base/build.sh +++ b/docker/base/build.sh @@ -45,22 +45,40 @@ else cd $GOPATH_ROOT/$1 # Switch over the code-base to another checkout if requested - if [ "$REPO_REMOTE" != "" ]; then - echo "Switching over to remote $REPO_REMOTE..." - if [ -d ".git" ]; then - git remote set-url origin $REPO_REMOTE - git pull - elif [ -d ".hg" ]; then - echo -e "[paths]\ndefault = $REPO_REMOTE\n" >> .hg/hgrc - hg pull + if [ "$REPO_REMOTE" != "" ] || [ "$REPO_BRANCH" != "" ]; then + # Detect the version control system type + IMPORT_PATH=$1 + while [ "$IMPORT_PATH" != "." ] && [ "$REPO_TYPE" == "" ]; do + if [ -d "$GOPATH_ROOT/$IMPORT_PATH/.git" ]; then + REPO_TYPE="git" + elif [ -d "$GOPATH_ROOT/$IMPORT_PATH/.hg" ]; then + REPO_TYPE="hg" + fi + IMPORT_PATH=`dirname $IMPORT_PATH` + done + + if [ "$REPO_TYPE" == "" ]; then + echo "Unknown version control system type, cannot switch remotes and branches." + exit -1 fi - fi - if [ "$REPO_BRANCH" != "" ]; then - echo "Switching over to branch $REPO_BRANCH..." - if [ -d ".git" ]; then - git checkout $REPO_BRANCH - elif [ -d ".hg" ]; then - hg checkout $REPO_BRANCH + # If we have a valid VCS, execute the switch operations + if [ "$REPO_REMOTE" != "" ]; then + echo "Switching over to remote $REPO_REMOTE..." + if [ "$REPO_TYPE" == "git" ]; then + git remote set-url origin $REPO_REMOTE + git pull + elif [ "$REPO_TYPE" == "hg" ]; then + echo -e "[paths]\ndefault = $REPO_REMOTE\n" >> .hg/hgrc + hg pull + fi + fi + if [ "$REPO_BRANCH" != "" ]; then + echo "Switching over to branch $REPO_BRANCH..." + if [ "$REPO_TYPE" == "git" ]; then + git checkout $REPO_BRANCH + elif [ "$REPO_TYPE" == "hg" ]; then + hg checkout $REPO_BRANCH + fi fi fi fi