2

We use Git and Jira in my office. Normally we use the create branch button to just create the branch. I have 2 python files I run, 1 on when a branch is created and 1 when it is merged and subsequently deleted.

My question is: How would I implement this as a hook for when a new branch is created (or first commit of a new branch) and when the branch is deleted? I was thinking that it would go under either update or post-recieve.

#Script
python foo.py --create
python foo.py --delete

Its as simple as that, but im not sure which part of the life cycle it would go in while looking at the different hooks available.

I was reading update.sample, post-update.sample, etc. I saw that in update.sample, there are two sections:

refs/heads/*,delete)
refs/heads/*,commit)

which i was thinking would be the sections i am interested in, given the variables referenced in those sections of code, but I was thinking that this could be a Local Commit / New Branch or Local Delete Branch, which doesnt work. I wanted to do this for like i said, after it occurs on the server.

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • you can use the update hook, https://stackoverflow.com/questions/14297606/git-hook-when-a-new-branch-is-created-and-or-pushed – Raúl Martín Jun 12 '18 at 18:19
  • `update` hook is serve-side, it works on pushing. – phd Jun 12 '18 at 20:09
  • So when looking at the *update* hook where do i place my create and delete script? I saw a comment for delete branch and a flag for that, but is the new branch one right above it? It just has a comment saying "Branch" – Fallenreaper Jun 12 '18 at 22:21

1 Answers1

1

You can see the exact parameters and conditions for the update hook here: it is a server-side hook, which means it will be triggered by a push to the Git repository hosting server.

If you are using an on premise instance of GitHub, you might need, as described here, to declare a global webhook instead, as you cannot easily add a hook on the server side when it comes to GitHub.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250