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

Feature Request: Add new configuration parameter --skip-regex #250

Open
sacha-c opened this issue May 14, 2023 · 0 comments · May be fixed by #251
Open

Feature Request: Add new configuration parameter --skip-regex #250

sacha-c opened this issue May 14, 2023 · 0 comments · May be fixed by #251

Comments

@sacha-c
Copy link

sacha-c commented May 14, 2023

I would like to introduce a new argument --skip-regex for similar purposes as the current --skip argument which just skips files.

I would be happy to make a contribution if this feature is of interest to you, let me know what you think

Use-case
I have a template and generated projects that have their dependencies automatically updated by renovate (similar to dependabot) and I want to keep the version updating responsibility with renovate and not through running cruft update.
As it currently stands, the template's dependencies are updated quite frequently by renovate which has the effect of failing the generated project's pipeline just as frequently; this is a problem because the generated projects do not care and will never apply these version updates in the template since they use renovate for this.
Since dependencies are stored in pyproject.toml which is used for various other configurations, I cannot just ignore the entire file. So, I would like to ignore only certain changes when updating using the template, hence the proposed use of regex.
In my scenario, I could then run cruft update with --skip-regex='"[^~]?((0|[1-9])\d*)(\.(0|[1-9])\d*)*.*"' which will filter out changes lines that contain strings like "^1.2.3".

Proposal
Add a new --skip-regex parameter in .cruft.json which does not apply changes that match the regex when running cruft update.

Implementation
I would modify the get_diff method to accept a skip_regex parameter, which would be used somewhat like so:
git diff | grep -E "<skip_regex>" --invert-match
(this is just an example, I would modify the code & methods appropriately)

The outcome here is that all changes matching the regex are excluded from the diff (modifications, additions & removals) which I think matches the expectations users will have when using this parameter.

For my particular use-case this means that version modifications are correctly ignored, however dependencies added or removed from the template will not be correctly applied to the generated project. This is unfortunate because I would like to have those changes, but I can live with that -- I don't see another solution.

Note that I also investigated some other approaches such as using git diff -S --pickaxe-regex or grepdiff, however these commands look for lines matching a regex in entire patches (afaik). This means that a change like this:

-  image: alpine/helm:3.10.1
+  image: alpine/helm:3.10.2
+  script: 
+    - echo 'I added a script'

Would be grouped in a patch and collectively ignored since one of those lines matches my version regex, which is not what we want.

Looking forward to knowing about your thoughts on this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant