绕过合并提交的预提交钩子 [英] bypass pre-commit hook for merge commits

查看:76
本文介绍了绕过合并提交的预提交钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一些git钩子以在预提交时运行一些gulp命令.我基本上运行jshint/plato.我基本上想在两种情况下绕过这些:

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. 修补程序分支(主/修补程序)
  2. git merge(或找到一种在合并提交时不会崩溃的方式)

plato gulp命令在源代码上运行分析,并生成一个/reports/目录,该目录跟踪一段时间内的复杂性.如果在修补程序分支上执行此操作,则将它们合并回开发时将导致合并冲突.简单的钩子在这里足以说明问题了:

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:

#!/bin/sh

if git diff --cached --name-only --diff-filter=ACM | grep '.js$' >/dev/null 2>&1
then
  git stash -q --keep-index
  ./node_modules/.bin/gulp jshint
  RESULT=$?
  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
fi

exit 0

现在的问题是,如果我在报告"上存在合并冲突,并且我解决了合并All conflicts fixed but you are still merging.,然后提交,它将再次运行分析并分阶段执行提交,并且在提交时会引发错误:

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'读取:没有这样的文件或目录.

/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...

推荐答案

所以我刚刚找到了一条我认为可以用来检测"merge_head"的命令

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

 git rev-parse -q --verify MERGE_HEAD

如果rev-parse返回哈希值,则表示我们当前处于合并状态.我可以用它绕过这个逻辑.但将等待更多有经验的个人提供更好的建议.

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.

这篇关于绕过合并提交的预提交钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆