I applied some static code analysis - and converted all the fields of the Java package level to secure ones. This is mostly correct, since I forgot to set the access modifier explicitly, and in the general case I protected it as usual.
Unfortunately, the refactoring I used is IntelliJ access modifiers, and it also changes the set of public → protected, on the constructors, etc.
So, one day I have a diff with the following statements in it:
-int myField; +protected int myField;
and
-public MyConstructor() +protected MyConstructor()
Is there a way to write a script that is executed during commit, and allows only the first example above, but not the second? I can define a script, and I'm just not sure how to run it - is this a catch with capture?
If this is a pre-commit hook, how do you consider diff in such a script and accept / reject it based on greping for some string?
source share