Skip to content

Commit caaafa0

Browse files
Merge pull request #139 from devops-infra/copilot/fix-87
Add force_without_lease parameter to allow true --force push
2 parents 3fff599 + fc74270 commit caaafa0

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ RUN chmod +x /entrypoint.sh ;\
2222
add-apt-repository ppa:git-core/ppa ;\
2323
apt-get update -y ;\
2424
apt-get install --no-install-recommends -y \
25-
git \
26-
git-lfs ;\
25+
git ;\
26+
# Install git-lfs without post-install configuration to avoid dpkg errors
27+
apt-get download git-lfs ;\
28+
dpkg --unpack git-lfs*.deb ;\
29+
rm -f /var/lib/dpkg/info/git-lfs.postinst ;\
30+
dpkg --configure git-lfs ;\
31+
apt-get install -f --no-install-recommends -y ;\
32+
rm git-lfs*.deb ;\
2733
apt-get clean ;\
2834
rm -rf /var/lib/apt/lists/*
2935

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Features:
4747
commit_prefix: "[AUTO]"
4848
commit_message: "Automatic commit"
4949
force: false
50+
force_without_lease: false
5051
target_branch: update/version
5152
```
5253
@@ -58,7 +59,8 @@ Features:
5859
| amend | No | `false` | Whether to make amendment to the previous commit (`--amend`). Cannot be used together with `commit_message` or `commit_prefix`. |
5960
| commit_prefix | No | `""` | Prefix added to commit message. Combines with `commit_message`. |
6061
| commit_message | No | `""` | Commit message to set. Combines with `commit_prefix`. Cannot be used together with `amend`. |
61-
| force | No | `false` | Whether to use force push for fast-forward changes (`--force`). Use only if necessary, e.g. when using `--amend`. And set `fetch-depth: 0` for `actions/checkout`. |
62+
| force | No | `false` | Whether to use force push with lease (`--force-with-lease`). Use only if necessary, e.g. when using `--amend`. And set `fetch-depth: 0` for `actions/checkout`. |
63+
| force_without_lease | No | `false` | Whether to use force push without lease (`--force`). Use only when you need to overwrite remote changes. Potentially dangerous. |
6264
| no_edit | No | `false` | Whether to not edit commit message when using amend (`--no-edit`). |
6365
| organization_domain | No | `github.com` | Github Enterprise domain name. |
6466
| target_branch | No | *current branch* | Name of a new branch to push the code into. Creates branch if not existing. |

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
description: Whether to force push
2727
required: false
2828
default: "false"
29+
force_without_lease:
30+
description: Whether to force push without lease (--force instead of --force-with-lease)
31+
required: false
32+
default: "false"
2933
no_edit:
3034
description: Whether to not edit commit message when using amend
3135
required: false

entrypoint.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ echo " amend: ${INPUT_AMEND}"
1111
echo " commit_prefix: ${INPUT_COMMIT_PREFIX}"
1212
echo " commit_message: ${INPUT_COMMIT_MESSAGE}"
1313
echo " force: ${INPUT_FORCE}"
14+
echo " force_without_lease: ${INPUT_FORCE_WITHOUT_LEASE}"
1415
echo " no_edit: ${INPUT_NO_EDIT}"
1516
echo " organization_domain: ${INPUT_ORGANIZATION_DOMAIN}"
1617
echo " target_branch: ${INPUT_TARGET_BRANCH}"
@@ -76,8 +77,11 @@ if [[ -n ${FILES_CHANGED} ]]; then
7677
fi
7778

7879
# Push
79-
if [[ "${INPUT_FORCE}" == "true" ]]; then
80-
echo "[INFO] Force pushing changes"
80+
if [[ "${INPUT_FORCE_WITHOUT_LEASE}" == "true" ]]; then
81+
echo "[INFO] Force pushing changes without lease"
82+
git push --force origin "${BRANCH}"
83+
elif [[ "${INPUT_FORCE}" == "true" ]]; then
84+
echo "[INFO] Force pushing changes with lease"
8185
git push --force-with-lease origin "${BRANCH}"
8286
elif [[ -n ${FILES_CHANGED} ]]; then
8387
echo "[INFO] Pushing changes"

0 commit comments

Comments
 (0)