git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* post-update hook
@ 2008-11-13 15:53 Jeremy Ramer
  2008-11-13 17:08 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jeremy Ramer @ 2008-11-13 15:53 UTC (permalink / raw)
  To: git

I have a set up where I have a local git repo (local1) that I make
changes to and two public repos (remote1, remote2) that hold the
current state of the repo for other applications to access.  So my
plan is to make the change is local1, then
git commit
git push remote1 master
git push remote2 master

However, the remotes currently have master checked out so though the
repo gets updated the working directory does not.  I tried editting
the post-update hook as follows

#!/bin/sh
echo Update changes...
git checkout master .

but it does not seem to make any difference.  Am I missing something
in the way post-update works?  It would be really nice to get this
working so I don't have to log into each remote and do a pull.  local1
is running git version 1.6.0.2. remotes are running git version 1.5.6.

Thanks!
Jeremy

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: post-update hook
  2008-11-13 15:53 post-update hook Jeremy Ramer
@ 2008-11-13 17:08 ` Junio C Hamano
  2008-11-13 18:48   ` Jeremy Ramer
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2008-11-13 17:08 UTC (permalink / raw)
  To: Jeremy Ramer; +Cc: git

"Jeremy Ramer" <jdramer@gmail.com> writes:

> ...  I tried editting
> the post-update hook as follows
>
> #!/bin/sh
> echo Update changes...
> git checkout master .
>
> but it does not seem to make any difference.

By above do you mean you do not even see "Update changes...", or do you
mean you do see that message but "checkout"  does not seem to do anything?

I notice that you said you "tried _editing_"; did you also enable it?

If you enabled it, you would see "Update changes..." but notice that "git
checkout master" reports modifications.  Try adding "-f" between "checkout"
and "master".

> ...  Am I missing something
> in the way post-update works?

That, or in the way "checkout" works.

By the way, this is one reason why pushing directly into the checked out
branch of a non-bare repository is not optimal.  A recommended practice is
to make the automation pretend as if you did a pull from the remote,

> ...  It would be really nice to get this
> working so I don't have to log into each remote and do a pull.

without actually having to log into each remote and run "pull" there.

 * Realize that if you did go to the remote and run "pull", then the
   change from the local machine is copied (via the underlying "fetch"
   that is run by "pull") in "remotes/origin/master", not to the branch
   "master".  And then the result is merged.

   IOW, 

	remote$ git pull

   when fully spelled out, is:

	remote$ git fetch local1 master:remotes/origin/master
        remote$ git merge remotes/origin/master

   That is, "master" branch tip from local1 goes to remote branch
   "origin/master" at remote1, and it is merged to whatever is checked
   out.

 * Arrange that if you push from local1 to remote1, the above
   automatically happens, in post-update hook.  So

   (1) Do not push into 'master'; IOW, do not:

	local1$ git push remote1 master:master ;# BAD

       Instead, push into the remotes/origin/master, to mimic _as if you
       fetched in the opposite direction_, like so:

	local1$ git push remote1 master:refs/remotes/origin/master

       Notice that this corresponds to what happens in the "git fetch"
       phase if you pulled in the reverse.  So all the hook needs to do is
       to merge.

   (2) Arrange post-update on the remote end to run the merge, when a push
       came to "origin/master", something like:

	#!/bin/sh
        case " $* " in
        *' refs/remotes/origin/master '*)
        	cd .. ;# you would be in .git -- go to the root of tree
                git merge refs/remotes/origin/master
                ;;
	esac

        I didn't test this, though...

The advantage of doing it this way is that you can configure it so that it
does not matter in which direction you actually work.  When you _do_ have
to go to the remote side to get the changes from local (perhaps on some
emergency that keeps you at remote), you can do a "git pull local" and you
can expect that the exact same thing as what your post-update script
ordinarily does happens.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: post-update hook
  2008-11-13 17:08 ` Junio C Hamano
@ 2008-11-13 18:48   ` Jeremy Ramer
  2008-11-13 22:06     ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Jeremy Ramer @ 2008-11-13 18:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Thu, Nov 13, 2008 at 10:08 AM, Junio C Hamano <gitster@pobox.com> wrote:
> "Jeremy Ramer" <jdramer@gmail.com> writes:
>
>> ...  I tried editting
>> the post-update hook as follows
>>
>> #!/bin/sh
>> echo Update changes...
>> git checkout master .
>>
>> but it does not seem to make any difference.
>
> By above do you mean you do not even see "Update changes...", or do you
> mean you do see that message but "checkout"  does not seem to do anything?
>
> I notice that you said you "tried _editing_"; did you also enable it?
>
> If you enabled it, you would see "Update changes..." but notice that "git
> checkout master" reports modifications.  Try adding "-f" between "checkout"
> and "master".

I did see the "Update changes..."  I enabled the post-update script. Sorry for
not being clear about that.

>> ...  Am I missing something
>> in the way post-update works?
>
> That, or in the way "checkout" works.
>
> By the way, this is one reason why pushing directly into the checked out
> branch of a non-bare repository is not optimal.  A recommended practice is
> to make the automation pretend as if you did a pull from the remote,
>
>> ...  It would be really nice to get this
>> working so I don't have to log into each remote and do a pull.
>
> without actually having to log into each remote and run "pull" there.
>
>  * Realize that if you did go to the remote and run "pull", then the
>   change from the local machine is copied (via the underlying "fetch"
>   that is run by "pull") in "remotes/origin/master", not to the branch
>   "master".  And then the result is merged.
>
>   IOW,
>
>        remote$ git pull
>
>   when fully spelled out, is:
>
>        remote$ git fetch local1 master:remotes/origin/master
>        remote$ git merge remotes/origin/master
>
>   That is, "master" branch tip from local1 goes to remote branch
>   "origin/master" at remote1, and it is merged to whatever is checked
>   out.

I thought I understood this process but I guess I didn't think it through
fully. What you are suggesting makes sense.

>
>  * Arrange that if you push from local1 to remote1, the above
>   automatically happens, in post-update hook.  So
>
>   (1) Do not push into 'master'; IOW, do not:
>
>        local1$ git push remote1 master:master ;# BAD
>
>       Instead, push into the remotes/origin/master, to mimic _as if you
>       fetched in the opposite direction_, like so:
>
>        local1$ git push remote1 master:refs/remotes/origin/master
>
>       Notice that this corresponds to what happens in the "git fetch"
>       phase if you pulled in the reverse.  So all the hook needs to do is
>       to merge.
>
>   (2) Arrange post-update on the remote end to run the merge, when a push
>       came to "origin/master", something like:
>
>        #!/bin/sh
>        case " $* " in
>        *' refs/remotes/origin/master '*)
>                cd .. ;# you would be in .git -- go to the root of tree
>                git merge refs/remotes/origin/master
>                ;;
>        esac
>
>        I didn't test this, though...

I had to make one change to this example to get it to work.  I'll put
it here for completeness

#!/bin/sh
case "$*" in
"refs/remotes/origin/master")
    cd ..
    GIT_DIR=".git"
    git merge refs/remotes/origin/master
    ;;
esac

>
> The advantage of doing it this way is that you can configure it so that it
> does not matter in which direction you actually work.  When you _do_ have
> to go to the remote side to get the changes from local (perhaps on some
> emergency that keeps you at remote), you can do a "git pull local" and you
> can expect that the exact same thing as what your post-update script
> ordinarily does happens.
>

Thanks for the quick response!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: post-update hook
  2008-11-13 18:48   ` Jeremy Ramer
@ 2008-11-13 22:06     ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2008-11-13 22:06 UTC (permalink / raw)
  To: Jeremy Ramer; +Cc: Junio C Hamano, git

"Jeremy Ramer" <jdramer@gmail.com> writes:

> I had to make one change to this example to get it to work.  I'll put
> it here for completeness
>
> #!/bin/sh
> case "$*" in
> "refs/remotes/origin/master")
>     cd ..
>     GIT_DIR=".git"
>     git merge refs/remotes/origin/master
>     ;;
> esac

Yeah, thanks for correction.  My bad not resetting GIT_DIR.

By the way, I _did_ write these seemingly extra spaces around $* and the
refname on purpose.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* post-update hook
@ 2009-06-07 13:39 Soham Mehta
  2009-06-07 13:40 ` post-rebase hook (correction from Re: post-update hook) Soham Mehta
  0 siblings, 1 reply; 8+ messages in thread
From: Soham Mehta @ 2009-06-07 13:39 UTC (permalink / raw)
  To: git

Wondering why there isn't a post-update (post-reset, post-cherrypick 
etc) hook in git? Is it only a matter of creating one, or is there a reason?

Thanks.
-Soham

^ permalink raw reply	[flat|nested] 8+ messages in thread

* post-rebase hook (correction from Re: post-update hook)
  2009-06-07 13:39 post-update hook Soham Mehta
@ 2009-06-07 13:40 ` Soham Mehta
  2009-06-07 20:41   ` Nanako Shiraishi
  0 siblings, 1 reply; 8+ messages in thread
From: Soham Mehta @ 2009-06-07 13:40 UTC (permalink / raw)
  To: git

Oops, I meant post-rebase hook

thus spake Soham Mehta , On 6/7/2009 6:39 AM:
> Wondering why there isn't a post-update (post-reset, post-cherrypick 
> etc) hook in git? Is it only a matter of creating one, or is there a 
> reason?
>
> Thanks.
> -Soham
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: post-rebase hook (correction from Re: post-update hook)
  2009-06-07 13:40 ` post-rebase hook (correction from Re: post-update hook) Soham Mehta
@ 2009-06-07 20:41   ` Nanako Shiraishi
  2009-06-07 22:37     ` Robin H. Johnson
  0 siblings, 1 reply; 8+ messages in thread
From: Nanako Shiraishi @ 2009-06-07 20:41 UTC (permalink / raw)
  To: Soham Mehta; +Cc: git

Quoting Soham Mehta <soham@box.net>:

> thus spake Soham Mehta , On 6/7/2009 6:39 AM:
>> Wondering why there isn't a post-update (post-reset, post-cherrypick
>> etc) hook in git? Is it only a matter of creating one, or is there a
>> reason?
>>
> Oops, I meant post-rebase hook

There are five valid reasons you might want a hook to a git operation.

http://thread.gmane.org/gmane.comp.version-control.git/70781/focus=71069

I don't think yours is backed by any of them.

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: post-rebase hook (correction from Re: post-update hook)
  2009-06-07 20:41   ` Nanako Shiraishi
@ 2009-06-07 22:37     ` Robin H. Johnson
  0 siblings, 0 replies; 8+ messages in thread
From: Robin H. Johnson @ 2009-06-07 22:37 UTC (permalink / raw)
  To: Git Mailing List

[-- Attachment #1: Type: text/plain, Size: 513 bytes --]

On Mon, Jun 08, 2009 at 05:41:48AM +0900, Nanako Shiraishi wrote:
> There are five valid reasons you might want a hook to a git operation.
> http://thread.gmane.org/gmane.comp.version-control.git/70781/focus=71069
> I don't think yours is backed by any of them.
That's a nice writeup. Could we consider adding this to the githooks
documentation?

-- 
Robin Hugh Johnson
Gentoo Linux Developer & Infra Guy
E-Mail     : robbat2@gentoo.org
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85

[-- Attachment #2: Type: application/pgp-signature, Size: 330 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-06-07 22:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-07 13:39 post-update hook Soham Mehta
2009-06-07 13:40 ` post-rebase hook (correction from Re: post-update hook) Soham Mehta
2009-06-07 20:41   ` Nanako Shiraishi
2009-06-07 22:37     ` Robin H. Johnson
  -- strict thread matches above, loose matches on Subject: below --
2008-11-13 15:53 post-update hook Jeremy Ramer
2008-11-13 17:08 ` Junio C Hamano
2008-11-13 18:48   ` Jeremy Ramer
2008-11-13 22:06     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).