views:

513

answers:

2

I have an idea of locking a repository from users pushing files into it by having a lock script in the GIT update hook since the push can only recognize the userid as arguments and not the branches. So i can lock the entire repo which is just locking a directory.

Is there a way to lock a specific branch in GIT?

Or is there a way an Update Hook can identify from which branch the user is pushing and to which branch the code is pushed?

+2  A: 

The update hook, from the docs:

The hook executes once for each ref to be updated, and takes three parameters:

  • the name of the ref being updated,
  • the old object name stored in the ref,
  • and the new objectname to be stored in the ref.

So... yes, it knows exactly what branch is being pushed, and can simply check that parameter and exit failure if it doesn't want the branch pushed to.

And if you want to (intelligently) do this before the user has uploaded the objects, you can use the pre-receive hook:

This hook executes once for the receive operation. It takes no arguments, but for each ref to be updated it receives on standard input a line of the format:

<old-value> SP <new-value> SP <ref-name> LF

where is the old object name stored in the ref, is the new object name to be stored in the ref and is the full name of the ref.

(those are spaces and line-feed)

Jefromi
This informational does help me, but update hook knows only the branch being pushed (source branch), is there a way to capture from the update hook, which branch the code is being pushed to (target branch)?
Senthil A Kumar
+2  A: 

A tool like gitolite has this kind of feature I believe: http://github.com/sitaramc/gitolite

amx
Thanks a lot, this does the job that is required. :)But i have other headaches of syncing these branches with ClearCase streams, which i think it's impossible if i have CC streams as different branches in one repo as compared to having one repo per stream.
Senthil A Kumar