pre-commit list only conflict solved files in a merge

79 Views Asked by At

I have a pre-commit hook in my Git repository that runs a lint check on every .php file affected in a commit. However, this hook also runs during merge commits, affecting all files modified in the merge. Often, when merging the master branch with numerous file changes, lint checks run on these files, which can be impractical.

My goal is to maintain lint checks for merge commits, but I only want the checks to run on files where conflicts were resolved or files explicitly edited by the user during the merge. In other words, I want to exclude lint checks on all files that were part of the merge but didn't have any user-initiated changes.

Currently, I'm using the following git diff command to list the files for linting:

git diff --cached --name-only --diff-filter=ACM -- '*.php'

Is there a way to modify this command or adjust my pre-commit hook to achieve the desired behavior? I want to maintain code quality while making the process more efficient during merge commits.

0

There are 0 best solutions below