4

I work on a git-lfs repository. Some colleagues occasionally need to update large binary files in this repository (hence git-lfs). Not all colleagues have git-lfs installed. They will not do it unless they need to. But once they want to commit/push, they have forgotten they need git-lfs... Which leads to "pollution" of the repository with actual files.

Is there a way to enforce the use of git-lfs by software? So I can only commit/push to the repo if I have git-lfs installed?

Edit: This question is similar Azure devops - server-side git hooks but I hoped there was a client-side solution. I thought the pre-commit hook could also be used for this.

Update: I see how git-hooks won't help because again I my collegues would need actively do something - which they probably won't. This explicit action is necessary because git-hooks would introduce massive security holes if not enabled with the users explicit consent. (https://stackoverflow.com/a/23771013/1635906)

Update: So I am ready to create a branch-policy which makes sure a CI build is executed. The build should fail if there are files that should be pointers. There is " List files not tracked by Git LFS " but it aims at bash. My Azure DevOps (on-premise) runs on windows and therefore cmd/powershell. I need a command that is similar to the behavior of the message I get on clone: "Encountered 11 file(s) that should have been pointers, but weren't" And then it should either print to STDERR or result in a non-zero exit code.

htho
  • 1,549
  • 1
  • 12
  • 33
  • That would depend on which git server you are using. Most have hooks you can enable to prevent pushes of certain file extensions or sizes. – fredrik Dec 08 '20 at 08:36
  • We use Azure DevOps (on-premise) – htho Dec 08 '20 at 08:40
  • DevOps is one of the few that does not support server side git hooks - or a variant thereof. Your best option is probably to require pull requests (by using branch policies) and implementing a pipeline or external approver service that makes the checks. It would at least prevent the pollution from reaching your main branch(es) – fredrik Dec 08 '20 at 08:46
  • see https://stackoverflow.com/questions/54213052/azure-devops-server-side-git-hooks – fredrik Dec 08 '20 at 08:47
  • You could prevent all too big files in a server-side hook but tell your co-workers to run a script that copies the hooks when they clone the repository. The hook could make sure lfs is installed on every commit. If people do not run the script and want to push a file, they simply cannot push. You can create a custom error measage in the server-side push hook. – dan1st Dec 08 '20 at 13:13

0 Answers0