bypass pre-commit hook for merge commits

I setup some git hooks to run some gulp commands on pre-commit. I basically run jshint/plato. I basically want to bypass these for two cases:

  1. hotfix branches (master / hotfix)
  2. git merge (or find a way to do it in a way that doesn’t crash on the merge commit case)

The plato gulp command runs analysis on the source and produces a /reports/ directory that tracks complexity over time. If we do this on the hotfix branch it will result in merge conflicts when merging them back into development. Enough talking here is the simple hook:

  • gitlab: how to change(reset) user info in terminal, and https push restricted
  • GitHub: What is a “wip” branch?
  • Why does git pull --rebase fail when replaying existing commits?
  • In git, how do I create a single patch for the last 2+ revisions?
  • How to forbid git commit if there are untracked files?
  • Git shows that a folder deleted, but git checkout <folder_name> can't bring it back?
  • #!/bin/sh
    if git diff --cached --name-only --diff-filter=ACM | grep '.js$' >/dev/null 2>&1
      git stash -q --keep-index
      ./node_modules/.bin/gulp jshint
      git stash pop -q
      [ $RESULT -ne 0 ] && exit 1
      git stash -q --keep-index
      ./node_modules/.bin/gulp plato
      git add report/
      git stash pop -q
    exit 0

    Issue right now is if i have a merge conflict on “reports” and I resolve the merge All conflicts fixed but you are still merging. and then commit it runs the analysis again and stages the commit and when it commits it throws an error:

    /Users/Nix/work/project/.git/modules/somesubmodule/MERGE_HEAD’ for reading: No such file or directory.

    The directory does exist but there is no merge head…

  • git-p4 and pulling from other repos
  • How to set current date as git commit message
  • Git Revert a Revert for a Merge
  • What to do when parent of branch was squashed?
  • Pull request on github - showing commits rebased from master
  • Combining non-linear commits into one commit (sausage making)
  • One Solution collect form web for “bypass pre-commit hook for merge commits”

    So I just found a command that I think i can use to detect the “merge_head”

     git rev-parse -q --verify MERGE_HEAD

    If rev-parse returns a hash that means we are currently in a merge state. I can use that to bypass this logic. But will wait for some better advice from more experienced individuals.

    Git Baby is a git and github fan, let's start git clone.