From 3099633675467ea6d9cbff225b1d41fededd8f0e Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Mon, 29 Jun 2020 14:59:11 +0200 Subject: [PATCH] download_and_compile.sh: fix the order of operations in _gitUpdate() _gitUpdate() used to call 'git pull' then 'git checkout'. If the latter command really did a branch switch, this could leave the local branch behind its remote counterpart (that was hopefully fetched by the 'git pull'). From now on, we do: git fetch origin git checkout --force "$branch" git pull --rebase (the --force option was already there before in the form of -f). This way, we can be sure that the local branch we check out is up-to-date when the function returns. Also replace short options by long ones for better readability of the code, and use Bash's [[ ... ]] conditional construct instead of [ ... ] for more efficiency---I think. Note: 'git stash save' is documented as deprecated in favor of 'git stash push', however the latter appears to have been introduced in 2017, therefore I believe it is too early to use it in download_and_compile.sh. --- download_and_compile.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/download_and_compile.sh b/download_and_compile.sh index b4225b5..17e82e0 100755 --- a/download_and_compile.sh +++ b/download_and_compile.sh @@ -260,19 +260,22 @@ function _gitUpdate(){ if [ "$DOWNLOAD" != "y" ]; then return fi - branch="$1" + + local branch="$1" set +e git diff --exit-code 2>&1 > /dev/null - if [ $? != 1 ]; then + if [[ $? != 1 ]]; then set -e - git pull -r - git checkout -f "$branch" + git fetch origin + git checkout --force "$branch" + git pull --rebase else set -e - git stash save -u -q - git pull -r - git checkout -f "$branch" - git stash pop -q + git fetch origin + git stash save --include-untracked --quiet + git checkout --force "$branch" + git pull --rebase + git stash pop --quiet fi }