Skip to content

Commit b1545df

Browse files
author
Eericxu
authored
Update upstream-sync.sh
1 parent 06208fb commit b1545df

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

upstream-sync.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,10 @@ fi
6666
# set user credentials in git config
6767
config_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
7975
git 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
8884
git 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

9187
if [ "${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
111107
echo '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}"
113109
echo 'Push successful' 1>&1
114110

115111
# reset user credentials for future actions

0 commit comments

Comments
 (0)