Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily lock a git repository

Tags:

git

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!

like image 988
schuess Avatar asked Aug 12 '13 16:08

schuess


1 Answers

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.

like image 86
Todd A. Jacobs Avatar answered Oct 11 '22 13:10

Todd A. Jacobs