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

[Feat]: file deletion #401

Closed
1 task
aairey opened this issue Oct 5, 2023 · 6 comments · Fixed by #435
Closed
1 task

[Feat]: file deletion #401

aairey opened this issue Oct 5, 2023 · 6 comments · Fixed by #435
Assignees
Labels
enhancement New feature or request

Comments

@aairey
Copy link

aairey commented Oct 5, 2023

Describe the feature

Support deleting files that were previously managed, now template-sync leaves the prior fil in place.

Use Case

Moved from .releaserc.json to .releaserc.yaml, the .releaserc.json stays in place but we want to remove it.

Proposed Solution

Optional delete option on the action?
Or delete by default (breaking change perhaps).

Acknowledgements

  • I may be able to implement this feature request
@AndreasAugustin
Copy link
Owner

Hi @aairey thanks for the feature request.

am not 100% sure if I completely understood the use case. So far I understood that you move a file within the source repository, within the target repository the new file will be present but the old file won't be removed. Is this correct?

The synchronization process is currently related to the git history. This means in detail that the move need to be tracked within the source repository. Did you try to do a git mv .releaserc.json .releaserc.yml to have the move within the git history? Possibly the git git_remote_pull_params command need to be changed. This would possibly keep the git history of the file.

What might work for your workflow with a small change is the hooks ability https://github.com/AndreasAugustin/actions-template-sync?tab=readme-ov-file#lifecycle-hooks.
We could add a precommit hook and with the hook you do the deletion in the target repo. The templatesync.yml file could be changed within the source repository (like add rm .releaserc.json ) but this will remove the git history of the file.

@thatryan-di
Copy link

I came to ask this same question. Just getting this set up and during testing I added a file called dummy.txt to my source repo then sync my target repo and it pulled in the new file. Awesome!
I then went back to source/template repo and deleted that dummy.txt file and then synced again but the test file did not get deleted from the repo.

@AndreasAugustin
Copy link
Owner

Hi @thatryan-di and thank you for your investigation.

Will have a closer look into the issue soon.

@AndreasAugustin
Copy link
Owner

AndreasAugustin commented Oct 30, 2023

Hi @aairey and @thatryan-di . Sorry for late answer.
I was able to reproduce the issue and track it down.

As a default pull command

git pull --allow-unrelated-histories --squash --strategy=recursive -X theirs <remote_repo> is used. It seems that the --squash is the responsible part.
Removing that option should solve your issue. So far it is possible with the git_remote_pull_params config parameter.
Removing the --squash should do the trick (possible after 2nd run).

I will think about removing --squash from the default and let the user decide at merge time if squash should be used.

There was a discussion/issue in the past #316 related to removing --squash. Back then I was not sure what is the better option.

@AndreasAugustin AndreasAugustin self-assigned this Oct 30, 2023
@AndreasAugustin AndreasAugustin added the bug Something isn't working label Oct 30, 2023
@AndreasAugustin
Copy link
Owner

Hi @aairey and @thatryan-di . Sorry for letting you wait. The issue is not super straight forward to solve.
The idea is currently to add the suggestion of @aairey (parameter to allow deletion) in combination with removing the squash option (out of convenience reasons).

The command git log --diff-filter D --pretty="format:" --name-only <source_revision>..HEAD | sed '/^$/d' should reveal the deleted files. With the knowledge of the deleted files within the base repository the actual deletion will be the easy part ;)

Need to do some final testing and the implementation also need to be done.

@AndreasAugustin AndreasAugustin added enhancement New feature or request and removed bug Something isn't working labels Nov 20, 2023
@AndreasAugustin AndreasAugustin removed their assignment Dec 30, 2023
@AndreasAugustin AndreasAugustin self-assigned this Jan 6, 2024
AndreasAugustin added a commit that referenced this issue Jan 8, 2024
AndreasAugustin added a commit that referenced this issue Jan 8, 2024
@AndreasAugustin
Copy link
Owner

AndreasAugustin commented Jan 18, 2024

Hi @aairey and @thatryan-di .
Sorry this task is taking some time... Somehow it is not trivial and unfortunately currently my free time is limited.

I somehow have a solution. You can try it with

name: actions-template-sync

on:
  # cronjob trigger At 00:00 on day-of-month 1. https://crontab.guru/every-month
  schedule:
    - cron: "0 0 1 * *"
  # manual trigger
  workflow_dispatch:

jobs:
  repo-sync:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
      # To use this repository's private action, you must check out the repository
      - name: Checkout
        uses: actions/checkout@v4
      - name: actions-template-sync
        uses: AndreasAugustin/actions-template-sync@file_deletion
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          source_repo_path: <your_repo>
          upstream_branch: main # defaults to main
          # git_remote_pull_params: --allow-unrelated-histories --strategy=recursive -X theirs --squash
          git_remote_pull_params: --allow-unrelated-histories --strategy=recursive --no-edit
          is_force_deletion: true

Please be aware that the git_remote_pull_params and using the version file_deletion in AndreasAugustin/actions-template-sync@file_deletion are (curently) important. The related changes: #435
Within my tests it is deleting the files. I did not find a solution so far which is working with all pull commands.

Maybe you find some time to do some tests. Thanks 🚀

AndreasAugustin added a commit that referenced this issue Feb 4, 2024
* feat: ✨ (#401) add option to force file deletion

* fix: 🐛 (#401)

* fix: 🐛 (#401)

* fix: 🐛 (#401) fix some small issues

* refactor: ♻️ enhance readability

* docs: 📝 (#401) some docs addons

* style: 🚨 lint issue
AndreasAugustin added a commit that referenced this issue Feb 4, 2024
* feat: ✨ (#401) add option to force file deletion

* fix: 🐛 (#401)

* fix: 🐛 (#401)

* fix: 🐛 (#401) fix some small issues

* refactor: ♻️ enhance readability

* docs: 📝 (#401) some docs addons

* style: 🚨 lint issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

3 participants