git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Jeremy Ramer" <jdramer@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: post-update hook
Date: Thu, 13 Nov 2008 09:08:50 -0800	[thread overview]
Message-ID: <7v7i77h7tp.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <b9fd99020811130753o13c5aa0cj79126a502d449cde@mail.gmail.com> (Jeremy Ramer's message of "Thu, 13 Nov 2008 08:53:28 -0700")

"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.

  reply	other threads:[~2008-11-13 17:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-13 15:53 post-update hook Jeremy Ramer
2008-11-13 17:08 ` Junio C Hamano [this message]
2008-11-13 18:48   ` Jeremy Ramer
2008-11-13 22:06     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2009-06-07 13:39 Soham Mehta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v7i77h7tp.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jdramer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).