0

I have a situation wherein my pre-receive hook script needs to allow only those files in commits whose name starts with Tag_

For example, I have a commit which contains 3 files,

Tag_a
Tagb
Tag_c

now my pre-receive script should allow only Tag_a and Tag_b but not Tagb.

I read somewhere on Stack Overflow that if we reject a file and allow the other files to be pushed, then the hash (sha1) value of the commit may change.

So my question is, is there a way to achieve this?

4

2 回答 2

1

Don't be sneaky. Just reject the whole commit, user should --amend commit to exclude disallowed files and try to push again.

于 2013-08-08T08:17:33.293 回答
0

A pre-receive or update hook can only accept or reject an entire ref-name. It's an all or nothing deal. You can inspect the proposed tree(s), but you'll have to figure out what the changes from the previous place the ref-name pointed-to might be.

For instance, if you get something saying refs/heads/zog is moving from d4df144c36f26c7887e5f8a74812f06a3b0338ec to 5e013711f5d6eb3f643ef562d49a131852aa4aa1, you'll need to see all the commits being added (or removed) between those points, and see what tree changes are being made in each commit. You can then decide that it's OK for the branch name to change, or that it is not OK, and that's basically it. The new commit might have the old one as its (single) parent, or it might have another new commit as its parent, which in turn has a third new commit, etc. (And any new commit may be a merge with multiple parents.)

于 2013-08-08T08:21:09.703 回答