简体   繁体   English

测试 git 的合并后挂钩脚本

[英]Testing a post-merge hooks script for git

I am very new to GIT, and I have the following doubt:我对GIT很陌生,我有以下疑问:

How can I test if a post-merge script will be doing its duty, without having other people pushing fake changes to the repository?我如何测试合并后脚本是否会执行其职责,而无需其他人将虚假更改推送到存储库? (Is post-merge the correct script, if I want it to be called every time I pull from the repository and some modifications are found? Will it be executed even if the pull exits with error, for example because of conflicts?) (合并后是否是正确的脚本,如果我希望每次从存储库中拉取并找到一些修改时都调用它?即使拉取因错误而退出,例如由于冲突,它也会执行吗?)

I ask this question related to this other problem I am facing .我问这个问题与我面临的另一个问题有关。

I would rather test that post-merger hook by pushing fake changes to a clone of your actual repo.我宁愿通过将虚假更改推送到实际存储库的克隆来测试合并后的挂钩。
I would register that hook in the clone the same way it is setup in the current repo.我会在克隆中注册该钩子,就像在当前 repo 中设置的一样。

That way, you don't pollute your original repo with fake history you would have to clean.这样,您就不会用必须清理的虚假历史记录污染您的原始存储库。


If you want to avoid the clone, you can:如果你想避免克隆,你可以:

  • dedicate a branch for those merges为这些合并指定一个分支
  • push after having changed user.name and user.email ( git config user.name xxx ), in order to simulate other authors and committers for your merges.在更改user.nameuser.email ( git config user.name xxx ) 后推送,以便为您的合并模拟其他作者和提交者。

Once those test merges are done on that branch, you can delete it easily enough .在该分支上完成这些测试合并后,您可以轻松地将其删除

No need for other people pushing anything to your repo.无需其他人向您的回购推送任何内容。 You can just create a local branch:您可以创建一个本地分支:

git checkout -b <dummy branch>

Make changes in your local branch, commit them, then move to your actual working branch and merge your dummy branch:在您的本地分支中进行更改,提交它们,然后移动到您的实际工作分支并合并您的虚拟分支:

git merge <dummy branch>

That should trigger your post-merge script.这应该会触发您的合并后脚本。 You can re-do this as much as you need to test your script without annoying anyone :)您可以根据需要重新执行此操作以测试您的脚本,而不会打扰任何人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM