From 5a952a4f53fc7366288db464ec120f755e9f1303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADcio=20Zimmerer=20Murta?= Date: Tue, 20 Jun 2023 11:44:39 -0300 Subject: [PATCH] Fixes issue while checking out subdirectory within default branch. This makes it so, when re-checking the active branch (which usually is the default branch or the one specified by the actions/checkout action), ensures that it is in sync with origin/ by passing -B instead of -b to git-checkout. --- github.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/github.sh b/github.sh index 553fce5..b2ed74b 100755 --- a/github.sh +++ b/github.sh @@ -182,9 +182,9 @@ elif git branch --list --remotes --format="%(refname)" | egrep -q "^refs/remotes update_branch=false fi - # explicitly using -b and --track origin/ ensures no + # explicitly using -B and --track origin/ ensures no # ambiguity when a local path matches the branch name. - git checkout --quiet -b "${branchname}" --track origin/"${branchname}" || fail_nl "unable to checkout the '${branchname}' branch." + git checkout --quiet -B "${branchname}" --track origin/"${branchname}" || fail_nl "unable to checkout the '${branchname}' branch." if ! ${update_branch}; then branchname="${targetbranch}-${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}" @@ -199,6 +199,7 @@ elif git branch --list --remotes --format="%(refname)" | egrep -q "^refs/remotes done echo -n "${branchname}, " + # this should _always_ be a new branch off the current one, thus -b. git checkout --quiet -b "${branchname}" || fail_nl "unable to switch to new branch '${branchname}'." fi echo "done."