There is a repository where you need to control its size and in case of exceeding the limit - block any changes. How to implement this?
Asked
Active
Viewed 338 times
1
-
If you reach the threshhold and block, then how will your development work continue? I think a better approach is to make sure that you keep really large and bad stuff out of the repo, e.g. large binary files. – Tim Biegeleisen Dec 13 '17 at 11:08
-
The task is to deliberately limit the size of the git repository. – Dima Kodnik Dec 13 '17 at 11:13
-
Instead of solving the problem by blocking, have you already looked at Git Virtual File System? https://github.com/Microsoft/GVFS This allows immense repositories to work perfectly. – Wouter de Kort Dec 13 '17 at 11:13
-
You could use a hook to check the combined size of tracked files. – Steve Dec 13 '17 at 11:14
-
Possible duplicate of [How to limit file size on commit?](https://stackoverflow.com/questions/39576257/how-to-limit-file-size-on-commit) – Steve Dec 13 '17 at 11:15
-
There was an idea to use the hook "update" on the server, and the size to be read by means of git or OS. – Dima Kodnik Dec 13 '17 at 11:33
-
Simply monitor the git repository and when it grows beyond the target size revoke push access for everyone. – Lasse V. Karlsen Dec 14 '17 at 07:05
-
1Also note that "the size of a repository" is a finicky thing since garbage collection and packing can make it go down as well. For instance, after growing to/beyond the target size, what if I force-push a branch back in time to get rid of commits, or delete some branches? Should you then allow changes yet again? – Lasse V. Karlsen Dec 14 '17 at 07:07
1 Answers
3
.git/hooks/pre-receive
#!/bin/bash
# size limit 2(Gb)
sizelimit_gb=2
reposize_kb=`git count-objects -v | grep 'size-pack' | sed 's/.*\(size-pack:\).//'`
let reposize_b=$reposize_kb*1024
let sizelimit_b=$sizelimit_gb*1024*1024*1024
if [ $reposize_b -gt $sizelimit_b ]; then
echo "Error: repository size > $sizelimit_gb Gb"
exit 1
#else
# echo "<= $sizelimit_gb Gb"
fi
exit 0
Above script must be saved as .git/hooks/pre-receive
in server, with execution permissions enabled (chmod +x .git/hooks/pre-receive
).

Dima Kodnik
- 63
- 5
-
I am getting a warning while running this script "warning: no corresponding .idx or .pack: /data/gitlab/git-data/repositories/@hashed/27/82/2782526eaa0c5c254b36d0c90e1f8c06af41d167a8b539bd3c81cd6d155e7e5f.git/objects/pack/pack-01293e2926b1a7766dae5863003f065107c78c32.bitmap" And Repo size is coming 0 instead of the actual size which is around 3GB something – Tanvi Agarwal Nov 19 '21 at 05:14
-