暂时锁定一个git存储库 [英] Temporarily lock a git repository

查看:208
本文介绍了暂时锁定一个git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知道是否有办法阻止提交到本地git存储库?在我的构建环境中,我通过它运行了一些git命令,如果用户在构建过程中进行了提交,它就会中断。



我想锁定存储库

谢谢!

解决方案

div>

TL; DR



这不是Git兼容的工作流程。如果你想要一个带有锁定的SCM,可以使用其他集中式存储库模型。一些支持可选锁的SCM包括 SVN CVS 和RCS。



不要推送到非裸库



除非您使用配置了 core.sharedRepository 启用后,您应该推送到裸仓库并运行任何持续集成或从非裸机克隆中构建系统。根据定义,任何共享存储库都可以通过具有必要权限的任何人修改工作目录,所以如果您需要在某个进程的生命周期中确保稳定的工作目录,则不应使用共享存储库。



共享存储库模型肯定存在一些用例。然而,你的不是其中之一。



滥用信号量共享存储库



你当然可以设计你自己的脚本滥用共享存储库模型。例如,您可以在封装脚本中使用信号量文件(例如,由 lockfile-progs 包中的 lockfile 创建的文件)或 flock 在启动一些长时间运行的构建过程之前,关闭对共享目录的写入或执行权限。这对于一个非常小的回报来说是很多工作,因为使用克隆可以减少工作量,从而获得同样的好处。然而,它在技术上是可行的,所以我在这里提到它是完整的。


Do you know if there is a way to block committing to a local git repository? In my build environment, I'm running some git commands through it and it breaks if the user makes a commit during the build.

I would like to lock the repository while the build is in progress then unlock when the build is finished.

Thanks!

解决方案

TL;DR

That is not a Git-compatible work-flow. If you want an SCM with locking, use something else with a centralized-repository model. Some SCMs that support optional locks include SVN, CVS, and RCS.

Don't Push to Non-Bare Repositories

Unless you are using a shared repository configured with core.sharedRepository enabled, you should be pushing to a bare repository and running any continuous integration or build systems off a non-bare clone. By definition, any shared repository can have the working directory modified by anyone with the necessary permissions, so you shouldn't be using a shared repository if you need to ensure a stable working directory during the lifetime of some process.

There are certainly some use cases for the shared repository model. However, yours is not one of them.

Abusing Shared Repositories with Semaphores

You could certainly design your own scripts to abuse the shared-repository model. For example, you might use semaphore files (such as those created by lockfile from the lockfile-progs package) or flock in a wrapper script that turns off write or execute permissions on your shared directory before kicking off some long-running build process. That's a lot of work for a very small pay-off, since you could get the same benefit with less work with a clone. However, it is technically feasible, so I mention it here for completeness.

这篇关于暂时锁定一个git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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