amitfin / patch

Home Assistant Integration for patching HA's files
MIT License
3 stars 1 forks source link

Git DIffs #71

Closed EvanSchalton closed 1 month ago

EvanSchalton commented 2 months ago

Checklist

Is your feature request related to a problem? Please describe.

I want to be able to patch sections of a file, e.g. https://github.com/schmittx/home-assistant-eero/pull/95/files

Describe the solution you'd like

Git has a robust diff and patching scheme: https://www.specbee.com/blogs/how-create-and-apply-patch-git-diff-and-git-apply-commands-your-drupal-website

Describe alternatives you've considered

Right now I've manually updated the file in my custom_integrations folder, but on update those changes will be wiped out.

Additional context

I just sat down to build a HACS plugin that uses git patch files to apply patches to HA Core & HA Integrations and saw that you've already written this extension which seems to strictly replace files.

Before I go down the path of creating a new extension which would have overlapping utility to your I thought I'd reach out and see if you were interested in extending this integration to include git diff/patch support. The unknown, for me, is if git is available in HA or if it'd need to be installed alongside the integration (that'd be a potential sticking point)

Random aside: for your file checks instead of using ~file_lines == other_file_lines, you can use the hash value / md5 checksum. Although w/ git diffs the files could have changed and as long as the patched lines weren't impacted the patch would still apply.

amitfin commented 2 months ago

PRs with additional functionality are welcome.

It's not so clear how git commands can be used here as there is not .git directory inside HA's installation. Maybe patch is a more promising approach. However, please note that the patching process should determine if something was changed, so it can also initiate HA's restart. Otherwise, it shouldn't initiate HA's restart to prevent an endless loop of restarts. Anyway, I'll let you figure it out. Please let me know if you want my involvement earlier in the process.