build-hass/.pipeline/git-init.sh

45 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -e
if [[ -z "$1" ]]; then
HASS_REPO="core"
else
HASS_REPO="$1"
fi
if [[ "${USE_GITHUB}" != "true" ]]; then
HASS_GIT_URL="https://git.sudo.is/home-assistant"
else
HASS_GIT_URL="https://github.com/home-assistant"
fi
HASS_MAIN_BRANCH="dev"
LOCAL_PATH=$(git rev-parse --show-toplevel)
if [[ ! -d "${HASS_REPO}/.git" ]]; then
echo "cloning '$HASS_GIT_URL/${HASS_REPO}'... "
git clone -q $HASS_GIT_URL/${HASS_REPO}
echo "done"
else
git -C ${HASS_REPO}/ checkout .
git -C ${HASS_REPO}/ clean -fd
CURRENT_BRANCH=$(git -C ${HASS_REPO}/ rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" != "${HASS_MAIN_BRANCH}" ]]; then
git -C ${HASS_REPO}/ checkout $HASS_MAIN_BRANCH
fi
git -C ${HASS_REPO}/ remote rm origin || true
git -C ${HASS_REPO}/ remote add origin $HASS_GIT_URL/${HASS_REPO}
git -C ${HASS_REPO}/ pull origin $HASS_MAIN_BRANCH
fi
echo
echo "HASS remote: '$HASS_GIT_URL/${HASS_REPO}'"
echo "HASS local: '$LOCAL_PATH/${HASS_REPO}'"
echo "HASS branch: '$(git -C ${HASS_REPO}/ rev-parse --abbrev-ref HEAD)'"
echo