| OLD | NEW |
| (Empty) |
| 1 #!/bin/sh | |
| 2 | |
| 3 CORE_REPONAME=$1 | |
| 4 MAIN_BRANCH=$2 | |
| 5 ORIGIN_URL=git@github.com:${CIRCLE_PROJECT_USERNAME}/${CORE_REPONAME}.git | |
| 6 | |
| 7 pushd ${HOME} | |
| 8 | |
| 9 # Kitt-core checkout folder "../kitt-core" is CACHED (see circle.yml). | |
| 10 # Must cover all 3 possible states of the repo | |
| 11 if [ -d "${CORE_REPONAME}" ]; then | |
| 12 # Cached folder does exist | |
| 13 cd ${CORE_REPONAME} | |
| 14 if [ ! -d ".git" ]; then | |
| 15 # but has lost git knowledge, recreate it | |
| 16 echo "Core folder exists but is not git repo, adding remote" | |
| 17 git init | |
| 18 git remote add origin ${ORIGIN_URL} | |
| 19 fi | |
| 20 # update from git, original or recreated | |
| 21 echo "Fetching core repo origin" | |
| 22 git fetch origin | |
| 23 else | |
| 24 # Cached folder does not exist (was not in cache yet), create new | |
| 25 echo "Core folder does not exist, cloning" | |
| 26 git clone ${ORIGIN_URL} | |
| 27 cd ${CORE_REPONAME} | |
| 28 fi | |
| 29 | |
| 30 # Check out as similar kitt-core branch as the one of main adblock repo | |
| 31 if [ "$MAIN_BRANCH" == "master" ]; then | |
| 32 # master is already checked out by default upon git clone | |
| 33 # (no remote -t) | |
| 34 echo "Checking out local master" | |
| 35 git checkout -f master | |
| 36 else | |
| 37 # does the same branch exist in kitt-core ? | |
| 38 CORE_BRANCH=$(git branch -r | grep "${MAIN_BRANCH}$") | |
| 39 if [ -z "$CORE_BRANCH" ]; then | |
| 40 echo "Main branch '$MAIN_BRANCH' does not exist in '$CORE_REPONAME'" | |
| 41 case "$MAIN_BRANCH" in | |
| 42 release* ) | |
| 43 # fall back to newest release branch | |
| 44 # TECHNICALLY OBSOLETE BECAUSE THERE IS ALWAYS ONLY ONE RELEASE BRANCH | |
| 45 # WITHOUT VERSION NUMBER but kept for potential future changes | |
| 46 CORE_BRANCH=$(git branch -r | grep release | sort -g | tail -1) | |
| 47 echo "Will check out latest '$CORE_BRANCH'" | |
| 48 ;; | |
| 49 *) | |
| 50 # fall back to develop | |
| 51 echo "Will check out develop head" | |
| 52 CORE_BRANCH="origin/develop" | |
| 53 ;; | |
| 54 esac | |
| 55 fi | |
| 56 git checkout -f -t $CORE_BRANCH | |
| 57 fi | |
| 58 | |
| 59 popd | |
| OLD | NEW |