Skip to content

Commit 4999484

Browse files
fix: enhance force-with-lease handling for action-commit-push
1 parent 9eb562d commit 4999484

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ else
9898
fi
9999

100100
SKIP_BRANCH_CREATION=false
101+
RESET_REQUIRES_FORCE_WITH_LEASE=false
101102
if [[ -z ${FILES_CHANGED} && "${INPUT_AMEND}" != "true" && -z "${INPUT_TARGET_BRANCH}" ]] && ! input_true "${INPUT_ALLOW_EMPTY_COMMIT}"; then
102103
SKIP_BRANCH_CREATION=true
103104
BRANCH="$(get_current_branch)"
@@ -169,6 +170,7 @@ if [[ "${SKIP_BRANCH_CREATION}" != "true" ]]; then
169170
echo "[ERROR] Failed to hard reset '${BRANCH}' to origin/${MAIN_BRANCH}"
170171
exit 1
171172
}
173+
RESET_REQUIRES_FORCE_WITH_LEASE=true
172174
else
173175
echo "[INFO] Rebasing branch onto ${MAIN_BRANCH}..."
174176
git rebase "origin/${MAIN_BRANCH}" || {
@@ -249,8 +251,12 @@ fi
249251
if [[ "${INPUT_FORCE}" == "true" ]]; then
250252
echo "[INFO] Force pushing changes using --force"
251253
git push --force origin "${BRANCH}"
252-
elif [[ "${INPUT_FORCE_WITH_LEASE}" == "true" ]]; then
253-
echo "[INFO] Force pushing changes with lease"
254+
elif [[ "${INPUT_FORCE_WITH_LEASE}" == "true" || "${RESET_REQUIRES_FORCE_WITH_LEASE}" == "true" ]]; then
255+
if [[ "${RESET_REQUIRES_FORCE_WITH_LEASE}" == "true" && "${INPUT_FORCE_WITH_LEASE}" != "true" ]]; then
256+
echo "[INFO] Force pushing changes with lease (required after reset_target_branch=true)"
257+
else
258+
echo "[INFO] Force pushing changes with lease"
259+
fi
254260
git push --force-with-lease origin "${BRANCH}"
255261
elif [[ "${SKIP_BRANCH_CREATION}" != "true" && ( -n ${FILES_CHANGED} || "${INPUT_AMEND}" == "true" || -n "${INPUT_TARGET_BRANCH}" ) ]]; then
256262
echo "[INFO] Pushing changes"

0 commit comments

Comments
 (0)