threads / discuss / 40952

Post-receive hook for "git pull"

Subject: Post-receive hook for "git pull"

## tl;dr

3 messages between Dec 7, 2015 and Feb 12, 2016.

replies: 2people: 2as markdown or json

Stefan Monnier· Dec 7, 2015, 13:47 UTC · lore

I have a system here where it can be quite common to have thousands of branches in the remote repository, and where I'd like to update some local state according to the appearance of new branches (or updates of pre-existing ones).

Currently, I use a "git for-each-ref" after pulling and then check (for each one of those refs) if an update is warranted, but this can get slow with that many branches. Is there some way to get something like the post-receive hook to be run for "git pull", so that the script gets told directly which (remote tracking) branches have been modified/created?

        Stefan
Junio C Hamano· Dec 7, 2015, 19:54 UTC · re: Stefan Monnier · lore

Re: Post-receive hook for "git pull"

Stefan Monnier <monnier@iro.umontreal.ca> writes:
Show 10 quoted lines
> I have a system here where it can be quite common to have thousands of
> branches in the remote repository, and where I'd like to update some
> local state according to the appearance of new branches (or updates of
> pre-existing ones).
>
> Currently, I use a "git for-each-ref" after pulling and then check (for
> each one of those refs) if an update is warranted, but this can get slow
> with that many branches.  Is there some way to get something like the
> post-receive hook to be run for "git pull", so that the script gets told
> directly which (remote tracking) branches have been modified/created?

I do not think there is. But you could easily script along the lines of...

    #!/bin/sh
    git for-each-ref | sort >prestate
    git pull "$@"
    git for-each-ref | sort >poststate
    comm -12 prestate poststate
... or something like that, no?
Stefan Monnier· Feb 12, 2016, 13:39 UTC · re: Junio C Hamano · lore

Re: Post-receive hook for "git pull"

Show 9 quoted lines
>> I have a system here where it can be quite common to have thousands of
>> branches in the remote repository, and where I'd like to update some
>> local state according to the appearance of new branches (or updates of
>> pre-existing ones).
>> Currently, I use a "git for-each-ref" after pulling and then check (for
>> each one of those refs) if an update is warranted, but this can get slow
>> with that many branches.  Is there some way to get something like the
>> post-receive hook to be run for "git pull", so that the script gets told
>> directly which (remote tracking) branches have been modified/created?
> I do not think there is.  But you could easily script along the
> lines of...
Show 5 quoted lines
>     #!/bin/sh
>     git for-each-ref | sort >prestate
>     git pull "$@"
>     git for-each-ref | sort >poststate
>     comm -12 prestate poststate

Right, it kinda works, but it can break down in case of concurrent operations.

I really wish there was a way to get something like the post-receive hook to be called everytime new commits are added, regardless if it's due to a push, a pull, a commit, a fast-import, ...

        Stefan

← back to recent threads