From f0544d131aa042293af9d2cd88291a3ea9333884 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 22 Nov 2021 21:00:30 +0100 Subject: [PATCH] Allow pihole checkout to work even when upstream branches are rebased. This uses git reset --hard origin/... instead of git pull --no-rebase Signed-off-by: DL6ER --- advanced/Scripts/piholeCheckout.sh | 20 +++++++++---------- automated install/basic-install.sh | 31 ++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 4c0a4f40..442e5d44 100755 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -84,11 +84,11 @@ checkout() { echo -e " ${INFO} Shortcut \"dev\" detected - checking out development / devel branches..." echo "" echo -e " ${INFO} Pi-hole Core" - fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo " ${CROSS} Unable to pull Core development branch"; exit 1; } + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" "reset" || { echo " ${CROSS} Unable to pull Core development branch"; exit 1; } if [[ "${INSTALL_WEB_INTERFACE}" == "true" ]]; then echo "" echo -e " ${INFO} Web interface" - fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; } + fetch_checkout_pull_branch "${webInterfaceDir}" "devel" "reset" || { echo " ${CROSS} Unable to pull Web development branch"; exit 1; } fi #echo -e " ${TICK} Pi-hole Core" @@ -100,10 +100,10 @@ checkout() { # Shortcut to check out master branches echo -e " ${INFO} Shortcut \"master\" detected - checking out master branches..." echo -e " ${INFO} Pi-hole core" - fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo " ${CROSS} Unable to pull Core master branch"; exit 1; } + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" "reset" || { echo " ${CROSS} Unable to pull Core master branch"; exit 1; } if [[ ${INSTALL_WEB_INTERFACE} == "true" ]]; then echo -e " ${INFO} Web interface" - fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; } + fetch_checkout_pull_branch "${webInterfaceDir}" "master" "reset" || { echo " ${CROSS} Unable to pull Web master branch"; exit 1; } fi #echo -e " ${TICK} Web Interface" local path @@ -112,9 +112,9 @@ checkout() { chmod 644 /etc/pihole/ftlbranch elif [[ "${1}" == "core" ]] ; then str="Fetching branches from ${piholeGitUrl}" - echo -ne " ${INFO} $str" + echo -e " ${INFO} $str" if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then - echo -e "${OVER} ${CROSS} $str" + echo -e " ${CROSS} $str" exit 1 fi corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) @@ -136,12 +136,12 @@ checkout() { for e in "${corebranches[@]}"; do echo " - $e"; done exit 1 fi - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" "reset" elif [[ "${1}" == "web" ]] && [[ "${INSTALL_WEB_INTERFACE}" == "true" ]] ; then str="Fetching branches from ${webInterfaceGitUrl}" - echo -ne " ${INFO} $str" + echo -e " ${INFO} $str" if ! fully_fetch_repo "${webInterfaceDir}" ; then - echo -e "${OVER} ${CROSS} $str" + echo -e " ${CROSS} $str" exit 1 fi webbranches=($(get_available_branches "${webInterfaceDir}")) @@ -163,7 +163,7 @@ checkout() { for e in "${webbranches[@]}"; do echo " - $e"; done exit 1 fi - checkout_pull_branch "${webInterfaceDir}" "${2}" + checkout_pull_branch "${webInterfaceDir}" "${2}" "reset" elif [[ "${1}" == "ftl" ]] ; then local path local oldbranch diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5c317edc..04b241ef 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2014,6 +2014,8 @@ fetch_checkout_pull_branch() { directory="${1}" local branch branch="${2}" + local pull_or_reset + pull_or_reset="${3}" # Set the reference for the requested branch, fetch, check it put and pull it cd "${directory}" || return 1 @@ -2021,7 +2023,7 @@ fetch_checkout_pull_branch() { git stash --all --quiet &> /dev/null || true git clean --quiet --force -d || true git fetch --quiet || return 1 - checkout_pull_branch "${directory}" "${branch}" || return 1 + checkout_pull_branch "${directory}" "${branch}" "${pull_or_reset}" || return 1 } checkout_pull_branch() { @@ -2030,25 +2032,42 @@ checkout_pull_branch() { directory="${1}" local branch branch="${2}" + local pull_or_reset + pull_or_reset="${3}" local oldbranch cd "${directory}" || return 1 oldbranch="$(git symbolic-ref HEAD)" - str="Switching to branch: '${branch}' from '${oldbranch}'" + if [[ "${branch}" != "${oldbranch}" ]]; then + str="Switching to branch: '${branch}' from '${oldbranch}'" + else + str="Updating current branch: '${branch}'" + fi printf " %b %s" "${INFO}" "$str" git checkout "${branch}" --quiet || return 1 printf "%b %b %s\\n" "${OVER}" "${TICK}" "$str" # Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git) chmod -R a+rX "${directory}" - git_pull=$(git pull --no-rebase || return 1) + local git_pull + if [[ "${pull_or_reset}" == "reset" ]]; then + git_pull=$(git reset --hard "origin/${branch}" || return 1) - if [[ "$git_pull" == *"up-to-date"* ]]; then - printf " %b %s\\n" "${INFO}" "${git_pull}" + if [[ "$git_pull" == *"up-to-date"* ]]; then + printf " %b %s\\n" "${INFO}" "${git_pull}" + else + printf "%s\\n" "$git_pull" + fi else - printf "%s\\n" "$git_pull" + git_pull=$(git pull --no-rebase || return 1) + + if [[ "$git_pull" == *"up-to-date"* ]]; then + printf " %b %s\\n" "${INFO}" "${git_pull}" + else + printf "%s\\n" "$git_pull" + fi fi return 0