From 1a52a02f109b9c6a24a8ace789ce5f361b0c5bc7 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Mon, 5 Dec 2011 13:38:29 -0800 Subject: [PATCH] support gerrit style refs/changes/... for branch names To use a gerrit "branch" with devstack I would find the repo/remote and set it for the specific project. Example: https://review.openstack.org/2059 Would mean I update my localrc with the following settings: KEYSTONE_REPO=https://review.openstack.org/p/openstack/keystone KEYSTONE_BRANCH=refs/changes/59/2059/2 Change-Id: I0793415fb03cc08d1eb1a3faf1b8ec3e723beb31 --- stack.sh | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/stack.sh b/stack.sh index 15ab538..7d66e31 100755 --- a/stack.sh +++ b/stack.sh @@ -448,26 +448,35 @@ function git_clone { GIT_DEST=$2 GIT_BRANCH=$3 - # do a full clone only if the directory doesn't exist - if [ ! -d $GIT_DEST ]; then - git clone $GIT_REMOTE $GIT_DEST - cd $2 - # This checkout syntax works for both branches and tags - git checkout $GIT_BRANCH - elif [[ "$RECLONE" == "yes" ]]; then - # if it does exist then simulate what clone does if asked to RECLONE + if echo $GIT_BRANCH | egrep -q "^refs"; then + # If our branch name is a gerrit style refs/changes/... + if [ ! -d $GIT_DEST ]; then + git clone $GIT_REMOTE $GIT_DEST + fi cd $GIT_DEST - # set the url to pull from and fetch - git remote set-url origin $GIT_REMOTE - git fetch origin - # remove the existing ignored files (like pyc) as they cause breakage - # (due to the py files having older timestamps than our pyc, so python - # thinks the pyc files are correct using them) - find $GIT_DEST -name '*.pyc' -delete - git checkout -f origin/$GIT_BRANCH - # a local branch might not exist - git branch -D $GIT_BRANCH || true - git checkout -b $GIT_BRANCH + git fetch $GIT_REMOTE $GIT_BRANCH && git checkout FETCH_HEAD + else + # do a full clone only if the directory doesn't exist + if [ ! -d $GIT_DEST ]; then + git clone $GIT_REMOTE $GIT_DEST + cd $GIT_DEST + # This checkout syntax works for both branches and tags + git checkout $GIT_BRANCH + elif [[ "$RECLONE" == "yes" ]]; then + # if it does exist then simulate what clone does if asked to RECLONE + cd $GIT_DEST + # set the url to pull from and fetch + git remote set-url origin $GIT_REMOTE + git fetch origin + # remove the existing ignored files (like pyc) as they cause breakage + # (due to the py files having older timestamps than our pyc, so python + # thinks the pyc files are correct using them) + find $GIT_DEST -name '*.pyc' -delete + git checkout -f origin/$GIT_BRANCH + # a local branch might not exist + git branch -D $GIT_BRANCH || true + git checkout -b $GIT_BRANCH + fi fi }