git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "David Aguilar" <davvid@gmail.com>
To: "James Cloos" <cloos@jhcloos.com>
Cc: "Ivan Zorin" <ivan.a.zorin@gmail.com>, git@vger.kernel.org
Subject: Re: how to check remote git repo for updates without pull/fetch
Date: Sat, 20 Dec 2008 15:41:13 -0800	[thread overview]
Message-ID: <402731c90812201541r510170tbe1d56b7261e8146@mail.gmail.com> (raw)
In-Reply-To: <m3skoi21m3.fsf@lugabout.jhcloos.org>

2008/12/20 James Cloos <cloos@jhcloos.com>:
>
> #!/bin/bash
> #
> # does this git repo need a pull?
> #
> l=$(git log|head -1|awk '{print $NF}')
> r=$(git ls-remote origin heads/master|awk '{print $1}')
> test "${r}" != "${l}"
>
>
> -JimC
> --
> James Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6
>
>

Hello

Your script will report false positives if you run that in a branch
where you've made local commits since git log's output will list a
commit that's not on the remote side.  Thus it'lll say 'you need to
pull' when really what happened was that you committed locally and the
sha1 test is no longer equal.  This is one of the reasons why it's a
good idea to always keep your local master clean.

There's two things you can do:

1. assume that you always keep your local 'master' branch clean.
That'll let you quickly compare your local master versus origin's
master:

#!/bin/sh
remotemaster=$(git ls-remote origin heads/master | awk '{print $1}')
localmaster=$(git rev-parse master)
test "$remotemaster" = "$localmaster"


2. You might have a local branch that's not called master but is
tracking origin/master.  Or, your master branch might not be clean.
You can accomodate that workflow with:

#!/bin/sh
remotemaster=$(git ls-remote origin heads/master | awk '{print $1}')
branchpoint=$(git merge-base origin/master HEAD)
test "$remotemaster" = "$branchpoint"


The difference is that we're checking against the branch point.  If
origin/master is beyond the branch point then chances are you need to
pull.



---- off topic, but related ----

BTW one sound recommendation that I've heard on this list is that your
topic branches should really be free of any unrelated changes.
Pulling stuff in "just because" changes the branch.  It's no longer
just "topic" -- it's now "topic" + whatever they happened to push
upstream.  That has some implications in that it makes it harder to
review what exactly went into the specific topic/feature since the
branch's history now contains unrelated changes.

An advantage of keeping your topic branches clean is that you can run:

    git diff $(git merge-base HEAD origin/master)

in your topic branch and you'll see *only* the changes that went into
that branch.  If you get into the habit of pulling stuff in then
you'll see your changes *and* stuff you've pulled in, which probably
has nothing to do with the original topic/feature, etc. etc.

Anyways, this is an entirely different topic/conversation and might
not apply to your specific circumstance but I figured I'd mention it
nonetheless.


-- 
    David

  reply	other threads:[~2008-12-20 23:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-19 16:15 how to check remote git repo for updates without pull/fetch Ivan Zorin
2008-12-19 16:33 ` Shawn O. Pearce
2008-12-19 16:39 ` Ivan Zorin
2008-12-20 17:32 ` James Cloos
2008-12-20 23:41   ` David Aguilar [this message]
2008-12-21  0:02     ` Boyd Stephen Smith Jr.
2008-12-21  9:53     ` James Cloos

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

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

  git send-email \
    --in-reply-to=402731c90812201541r510170tbe1d56b7261e8146@mail.gmail.com \
    --to=davvid@gmail.com \
    --cc=cloos@jhcloos.com \
    --cc=git@vger.kernel.org \
    --cc=ivan.a.zorin@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.
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).