TLDR: git rev-parse -q --verify MERGE_HEAD
errors out when NOT in a merge state. How can I get a similar command that would error out when we're IN a merge state?
Problem: when I merge master into my branch and it has conflicts, I have to manually correct them, then commit. In some cases though, I have too many changes coming from master, so I'd rather just skip the pre-commit hooks.
Partial solution: I could just run git commit --no-verify
and get things merged, but that's because I know about the flag. Other developers might not know about it and so (1) they spend more time than needed waiting for the pre-commit hooks to run and (2) as it could take too long, they tend to be less likely to remerge master (assumption).
Almost definitive solution: I found a way to detect if I am in a merge state by using git rev-parse -q --verify MERGE_HEAD
. It returns a hash when in merge state, and errors out when NOT in merge state. But what I need is exactly the opposite. I need it to error out when I AM in a merge state, so I could add it as a pre-commit hook to all my hooks. That'd make them fail in the first line, then not execute the following command.
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"git rev-parse -q --verify MERGE_HEAD",
"eslint --max-warnings 0 --fix"
],
"*.scss": [
"git rev-parse -q --verify MERGE_HEAD",
"stylelint 'app/**/*.scss'"
],
"*.{js,json,yml,scss,md}": [
"git rev-parse -q --verify MERGE_HEAD",
"prettier --write"
],
"*": [
"bundle exec rubocop --auto-correct --force-exclusion"
]
},
Note that the above mentioned does not work. In order for it to work, all we need is to reverse the effect from git rev-parse -q --verify MERGE_HEAD
, i.e, it should error out when we are in a merge state. How can I do this in a simple command?