From ead0d0e20f7050dbd23f14092873452e8a349d7a Mon Sep 17 00:00:00 2001 From: Andy Augustin Date: Sat, 6 Jan 2024 12:50:49 +0100 Subject: [PATCH] feat: :sparkles: (#401) add option to force file deletion --- README.md | 3 ++- action.yml | 4 ++++ src/sync_template.sh | 12 +++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02ecd97c..9f68a005 100644 --- a/README.md +++ b/README.md @@ -247,9 +247,10 @@ jobs: | is_dry_run | `[optional]` set to `true` if you do not want to push the changes and not want to create a PR | `false` | | | is_allow_hooks | `[optional]` set to `true` if you want to enable lifecycle hooks. Use this with caution! | `false` | `false` | | is_not_source_github | `[optional]` set to `true` if the source git provider is not GitHub | `false` | `false` | +| is_force_deletion | `[optional]` set to `true` if you want to force delete files which are deleted within the source repository even if they contain changes" | `false` | `false` | | git_user_name | `[optional]` set the committer git user.name | `false` | `${GITHUB_ACTOR}` | | git_user_email | `[optional]` set the committer git user.email | `false` | `github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}` | -| git_remote_pull_params |`[optional]` set remote pull parameters | `false` | `--allow-unrelated-histories --squash --strategy=recursive -X theirs` | +| git_remote_pull_params |`[optional]` set remote pull parameters | `false` | `--allow-unrelated-histories --strategy=recursive -X theirs` | ### Docker diff --git a/action.yml b/action.yml index a4a23b5d..00c4e853 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,9 @@ inputs: is_not_source_github: description: "[optional] set to true if the source repository is not a github related repository. Useful e.q. if the source is GitLab" default: "false" + is_force_deletion: + description: "[optional] set to true if you want to force delete files which are deleted within the source repository even if they contain changes" + default: "false" git_user_name: description: "[optional] set the committer git user.name for the merge commit" git_user_email: @@ -62,6 +65,7 @@ runs: IS_DRY_RUN: ${{ inputs.is_dry_run }} IS_ALLOW_HOOKS: ${{ inputs.is_allow_hooks }} IS_NOT_SOURCE_GITHUB: ${{ inputs.is_not_source_github }} + IS_FORCE_DELETION: ${{ inputs.is_force_deletion }} GIT_USER_NAME: ${{ inputs.git_user_name }} GIT_USER_EMAIL: ${{ inputs.git_user_email }} GIT_REMOTE_PULL_PARAMS: ${{ inputs.git_remote_pull_params }} diff --git a/src/sync_template.sh b/src/sync_template.sh index 8408ecb2..131e9aa2 100644 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -32,7 +32,7 @@ if [[ -n "${SRC_SSH_PRIVATEKEY_ABS_PATH}" ]]; then export GIT_SSH_COMMAND="ssh -i ${SRC_SSH_PRIVATEKEY_ABS_PATH}" fi -GIT_REMOTE_PULL_PARAMS="${GIT_REMOTE_PULL_PARAMS:---allow-unrelated-histories --squash --strategy=recursive -X theirs}" +GIT_REMOTE_PULL_PARAMS="${GIT_REMOTE_PULL_PARAMS:---allow-unrelated-histories --strategy=recursive -X theirs}" cmd_from_yml_file "install" @@ -95,6 +95,16 @@ if [ -s "${TEMPLATE_SYNC_IGNORE_FILE_PATH}" ]; then fi echo "::group::commit changes" + +force_delete_files() { + warn "force file deletion is enabled. Deleting files which are deleted within the target repository" + git log --diff-filter D --pretty="format:" --name-only "${TEMPLATE_REMOTE_GIT_HASH}"..HEAD | sed '/^$/d' | xargs rm +} + +if [ "$IS_FORCE_DELETION" == "true" ]; then + force_delete_files +fi + git add . # we are checking the ignore file if it exists or is empty