Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to bypass post-merge git hook when executing `git merge` command

I have post-merge hook configured in order to integrate (semi-manually) with another version control system. However sometimes I would like to avoid the the hook from running is there some way to bypass it for git merge?

I knew there is --no-verify command line parameter for git commit. That kind of solution would be perfect for my use case but seems like --no-verify is not working for git commit command.

like image 682
Tim Avatar asked Oct 30 '15 06:10

Tim


2 Answers

There is no flag to disable running a post-merge hook, but you could easily rig your own post-merge hook (which you control completely, since it's in your own repository) to obey an environment variable. For instance, a shell script might start with:

#! /bin/sh
warn() {
    echo "warning: $1" 1>&2
}
case ${SKIP_POST_MERGE_HOOK:-no} in
yes) exit 0;;
no) ;;
*) warn "mystery value ${SKIP_POST_MERGE_HOOK} for SKIP_POST_MERGE_HOOK";;
esac
... rest of code as usual ...

Now if you want to run git merge but bypass the hook (or run something like the git pull convenience script that runs git merge for you), simply set SKIP_POST_MERGE_HOOK=yes for the duration:

$ SKIP_POST_MERGE_HOOK=yes git merge ...
like image 75
torek Avatar answered Nov 08 '22 04:11

torek


for those who came here because git merge --no-verify --continue doesn't work together - you can just disable hooks termporarily for the merge - e.g. for my current react project I just removed this part from my package.json - as file not staged it will not go into the merge commit

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,ts,tsx}": [
      "eslint --fix --rule '@typescript-eslint/no-non-null-assertion: error'",
      "prettier --write"
    ],
    "*.css": [
      "stylelint --fix",
      "prettier --write"
    ],
    "*.{json,yml,md,eslintrc,stylelintrc,babelrc}": [
      "prettier --write"
    ]
  },
like image 33
godblessstrawberry Avatar answered Nov 08 '22 04:11

godblessstrawberry