Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force push if set in environment #14

Merged
merged 6 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
args: "https://gitlab.com/<namespace>/<repository>"
env:
FORCE_PUSH: "false"
GITLAB_HOSTNAME: "gitlab.com"
GITLAB_USERNAME: "svboxel"
GITLAB_PASSWORD: ${{ secrets.GITLAB_PASSWORD }} // Generate here: https://gitlab.com/profile/personal_access_tokens
Expand All @@ -34,3 +35,5 @@ Be sure to define the `GITLAB_PASSWORD` secret in `https://github.com/<namespace
Before setup a token to use as `GITLAB_PASSWORD` here https://gitlab.com/profile/personal_access_tokens
The token must have `read_api`, `read_repository` & `write_repository` permissions in GitLab.
For granular permissions create seperate users and tokens in GitLab with restricted access.

If you're rewriting history in the primary repo (e.g by using `git rebase`), you'll need to force push. Set the `FORCE_PUSH` environment variable to `true` to enable this. This will overwrite history in the mirror as well, so be **careful with this** (just like any time you're using `git push --force`).
7 changes: 6 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ sh -c "git config --global core.askPass /cred-helper.sh"
sh -c "git config --global credential.helper cache"
sh -c "git remote add mirror $*"
sh -c "echo pushing to $branch branch at $(git remote get-url --push mirror)"
sh -c "git push mirror $branch"
if [ "$FORCE_PUSH" = "true" ]
then
sh -c "git push --force mirror $branch"
else
sh -c "git push mirror $branch"
fi

sleep $POLL_TIMEOUT

Expand Down