6666# set user credentials in git config
6767config_git
6868
69- # ensure target_branch is checked out
70- if [ $( git branch --show-current) != " ${INPUT_TARGET_BRANCH} " ]; then
71- git checkout ${INPUT_GIT_CHECKOUT_ARGS} " ${INPUT_TARGET_BRANCH} "
72- echo ' Target branch ' ${INPUT_TARGET_BRANCH} ' checked out' 1>&1
73- fi
69+ local_branch=" ${INPUT_TARGET_BRANCH} -for-upstream"
7470
75- # remove old upstream
76- git branch --set-upstream-to= origin/" ${INPUT_TARGET_BRANCH} "
71+ # switch to branch-for- upstream -> origin/branch
72+ git switch -c " ${local_branch} " --track origin/" ${INPUT_TARGET_BRANCH} "
7773
7874# sync code
7975git pull --rebase
@@ -86,7 +82,7 @@ git remote add upstream "${UPSTREAM_REPO}"
8682
8783# check latest commit hashes for a match, exit if nothing to sync
8884git fetch ${INPUT_GIT_FETCH_ARGS} upstream " ${INPUT_UPSTREAM_BRANCH} "
89- DIFF=$( git rev-list " ${INPUT_TARGET_BRANCH } ..upstream/${INPUT_UPSTREAM_BRANCH} " )
85+ DIFF=$( git rev-list " ${local_branch } ..upstream/${INPUT_UPSTREAM_BRANCH} " )
9086
9187if [ " ${DIFF} " = " " ]; then
9288 echo " ::set-output name=has_new_commits::false"
@@ -109,7 +105,7 @@ echo 'Sync successful' 1>&1
109105
110106# push to origin target_branch
111107echo ' Pushing to target branch...' 1>&1
112- git push ${INPUT_GIT_PUSH_ARGS} origin " ${INPUT_TARGET_BRANCH} "
108+ git push ${INPUT_GIT_PUSH_ARGS} origin HEAD: " ${INPUT_TARGET_BRANCH} "
113109echo ' Push successful' 1>&1
114110
115111# reset user credentials for future actions
0 commit comments