Temporarily lock a git repository

前端 未结 3 795
悲&欢浪女
悲&欢浪女 2021-02-20 17:17

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

3条回答
  •  北海茫月
    2021-02-20 18:08

    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.

提交回复
热议问题