I have applied some static code analysis - and transformed all Java package level fields into protected. This is mostly correct, as I forgot to set the access modifier explicitly, and protected is generally what I was after in those cases.
Unfortunately, the refactoring I applied was the IntelliJ weaken access modifiers on, and it also changes lots of public -> protected, on constructors and so on.
So once I have a diff with statements like this in it:
-int myField;
+protected int myField;
and
-public MyConstructor()
+protected MyConstructor()
Is there a way to write a script, that runs during the commit, and only lets the first example above, but no the second? I can figure out the script, and I am just not sure how to run it - is it a pre-commit hook?
If its a pre-commit hook, how do you examine the diff in such a script and accept/reject it based on greping it for some string?