2

I want to limit the storage of a git repository, to avoid a repository exceed a size limit. I've seen this question (How to prevent a Git repository growing above a maximum size?), in which this problem is solved using a pre-receive hook. But, if I lock the push as this way, the user will cannot remove files to recover space.

I've thinking in modify this pre-receive, calculating a estimation of the size of the repository after the push. But I don't know how can I get this new size. This estimation must consider the removed files, to allow the user can do a new push removing files to leave space.

Other way could be use a post-receive, which revert the changes if the new size exceed the limit. But, if the push includes more than one commit, this revert can be complex.

How can I solve this?

AlmuHS
  • 387
  • 6
  • 13
  • But this bundle doesn't allow me to see if the size has been reduced. By example, if the user has removed some files – AlmuHS Jan 18 '20 at 16:35
  • I would consider approaching this through something like an XFS project quota. – larsks Jan 18 '20 at 18:47
  • @larsks It's not possible, because the repositories are in a self-managed GitLab installation, and It's not possible reinstall It – AlmuHS Jan 18 '20 at 19:21
  • Add a commit adds a commit. The repository grows. Reverting a commit adds a new commit. The repository *grows*. Removing files adds a new commit. The repository *grows*. A version control system, by definition, saves *everything*, *forever*. – torek Jan 18 '20 at 20:21
  • Note that the only thing that can shrink the repository proper is to *remove* commits from it. But later commits depend on the existence of earlier commits, so in general, to strip commits from a repository, you strip that commit *and all its descendants*. Think of it as going back in time and making "now" be "then": the future hasn't happened, and you can no longer remember it. – torek Jan 18 '20 at 20:26
  • @tarek if the contents of the push hasn't been uploaded yet to the server, It's posible to do `git reset --hard` to remove the commit. In any case, the most secure option is directly reject the push, in the pre-receive hook – AlmuHS Jan 18 '20 at 21:12

0 Answers0