1

I have a git repository and i want to launch an hook when someone is trying to push on a specific branch. ( pre-receive hook, check branch, refuse if it's master branch. )

Is there any variables where i can get pushed branch on server side when users, on his $git clone use $git push ?

Thanks.

Delfalso
  • 175
  • 1
  • 2
  • 13

1 Answers1

1

Due to the structure of git, you will be aware of user changes first, when the user pushes its changes to the remote. So the only way to safely handle this condition is using server-side-hooks.

The client-side-hooks reside in a hidden folder of your repository, so you have unfortunately no control over it.

A nearly similar question was asked once before.

You are able to act on updates on different branches (refs) by using the update-script.

Community
  • 1
  • 1
Florian Neumann
  • 5,587
  • 1
  • 39
  • 48
  • I actually want to use pre-receive hook, but can i know on what branch user is pushing when pre-receive hook is called? – Delfalso Apr 29 '14 at 14:05
  • In the update-script you're able to act on updates to single branches and to revoke them. – Florian Neumann Apr 29 '14 at 14:08
  • 1
    @Delfalso The documentation for the pre-receive hook (`git help hooks`) explains what input (and the specific format of that input) the hook receives when it runs. This includes the names of the branches that will be updated and how they will be updated, provided the hook script allows the change... It also documents the update hook that @florianb is referring to. – twalberg Apr 29 '14 at 14:17
  • @Delfalso: here's an example how to use the pre-receive-hook: https://gist.github.com/caniszczyk/1327469 With a few changes you might refuse whatever pushes you want. – Florian Neumann Apr 29 '14 at 14:20
  • @florianb @twalberg Work with `update` hook ! We can get branch name with `$1` in a script . Thanks ! – Delfalso Apr 30 '14 at 08:27