Reputation: 220
I have a central git repo in which I deleted its old history, causing all the sha IDs to be changed. So I have a new first commit. I want to prevent people from pushing the old history to this new repo (it will have a different first commit).
I can get the sha1 of the first commit using:
git log --pretty=format:"%H @ %ai (%an)" | tail -1
How can I get the directory of the clone in the pre-receive hook?
Upvotes: 1
Views: 56
Reputation: 1324657
You can add a pre-receive hook which reads each received ref.
If the first received head has no parent, that means someone is pushing the all history of the master branch, instead of a few commits.
git rev-list $new-ref
(It should return only itself, if $new-ref
is a root commit, with no parent)
If that is the case, reject the commit (exit 1
).
If not, don't block the push.
Upvotes: 1