phillipuniverse / githook-maven-plugin

Maven plugin to install local git hooks
MIT License
28 stars 1 forks source link

Configuration option to set overwrite #6

Open dwightmulcahy opened 5 years ago

dwightmulcahy commented 5 years ago

something like this

                        <configuration>
                            <overwrite>true</overwrite>     <==== true/false
                            <hooks>
                             ...
                            </hooks>
                        </configuration>

should create an ERROR (but continue) if overwrite==true and file exists...

dwightmulcahy commented 5 years ago

depending on if #7 is implemented it might be better to have something like <overwrite-strategy> that would allow overwrite, chain, backup, etc...

phillipuniverse commented 5 years ago

Somewhat related to this, the plugin shouldn't do anything at all if the hash of the existing hook matches what it's trying to write (only do file modifications if necessary).

Also, I think the default behavior should be to overwrite, but maybe warn or prompt or something if it's the first time it's happening? There are 2 use cases of "existing" hooks:

A hook that this plugin didn't write

  1. User throws the plugin into their pom.xml
  2. We try to install the hook; oh wait there's already an existing hook there, the user forgot that they had it. Maybe we error on this case?

A hook the plugin did write, but now there's an update

  1. User has been using the plugin just fine, hooks are happening
  2. They need to update the hook that the plugin manages, this should always overwrite

    Use case: maybe the pre-commit hook takes a few seconds to run, v1 of the hook doesn't have any progress indicators, now the user writes v2 with progress indicators

Maybe we can differentiate between those 2 cases with a comment at the top of the file like #written by githook-maven-plugin. Need to think about upgradeability though, people have been using this plugin already and their existing hooks will not have this header.