有没有办法检查 git 标签是否与相应提交的内容匹配?
在我工作的公司中,某些项目有一个 project.info
文件,其中包含程序/库/其他内容的当前版本。
实际上,当有人想要标记一个版本时,他必须首先确保 project.info
文件(已版本化)是最新的,并且包含与他所标记的名称相同的版本。即将创建。不用说这很容易出错。
我们致力于 git 的客户端-服务器工作流程(所有提交都转到同一个中央存储库),所以我想知道:有没有一种方法(也许是一个钩子?)使这个中央存储库拒绝 project.info 的标签
不匹配?
我应该注意什么才能开始?
非常感谢。
In the company I work for, some projects have an project.info
file which contains the current version of the program/library/whatever.
Actually, when someone wants to tag a version, he must first ensure that the project.info
file (which is versionned) is up-to-date and contains the same version than the name of the tag he is about to create. No need to say that this is error prone.
We work on a clients-server workflow for git (all commits go to the same central repository) so I wonder: is there a way (a hook perhaps ?) to make this central repository refuse tags for which the project.info
does not match ?
What should I look for to get started ?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢这里所有的建议,我成功了。
这是我的最终
update
钩子脚本:这是我的
extract_project_version
脚本:现在它完美运行:)
Thanks to all the advices here, I succeeded.
Here is my final
update
hook script:And here is my
extract_project_version
script:And now it works perfectly :)
服务器端
如果您计划使用挂钩,接收后挂钩(服务器引用已更新)可以在
project.info 如果它已被忘记,但初始标记提交在文件中不会有正确的信息...
如果您想在更新引用之前验证这一点,问题在于预接收/更新挂钩< /strong> 实际上没有所需的信息检查
project.info
的有效性(它们获取正在更新的 ref 的名称、存储在 ref 中的旧对象名称以及要存储在 ref 中的新对象名称)。您可以在此处找到一些挂钩示例和那里有一些信息。
关于此主题的其他一些 Stack Overflow 主题:
客户端
这不能确保任何事情,因为客户端可能决定不应用正确的方法。尽管如此,提交后挂钩也许可以解决这个问题。
Server-side
If you plan on using hooks, a post-receive hook (server refs updated) could create a commit with a change on
project.info
if it has been forgotten, but the initial tagging commit would not have the right information in the file...If you want to validate this before updating the refs, the problem is that pre-receive/update hooks do not actually have the information required to check the validity of
project.info
(they get the name of the ref being updated, the old object name stored in the ref and the new objectname to be stored in the ref).You can find some examples of hooks here and some information there.
Some other Stack Overflow topics on this subject :
Client-side
This would not ensure anything since clients could decide not to apply the proper method. Still, a post-commit hook could probably do the trick.