Re: how to check remote git repo for updates without pull/fetch
From: James Cloos <hidden>
Date: 2016-06-15 22:45:48
Here is the script I use:
3 messages, 3 authors, 2016-06-15 · open the first message on its own page
From: James Cloos <hidden>
Date: 2016-06-15 22:45:48
Here is the script I use:
From: David Aguilar <hidden>
Date: 2016-06-15 22:45:48
2008/12/20 James Cloos [off-list ref]:
#!/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 [off-list ref] 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
From: Boyd Stephen Smith Jr. <hidden>
Date: 2016-06-15 22:45:48
On Saturday 2008 December 20 17:41:13 David Aguilar wrote:
2008/12/20 James Cloos [off-list ref]:quoted
#!/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 [off-list ref] OpenPGP: 1024D/ED7DAEA6Hello 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.
Change the last line to:
test "${r}" != "$(git merge-base "${r}" "${l}")" and those false positives
should go away.
The script is far from a complete solution to the OPs problem though. It only
checks one, specific remote branch. It only checks against the current
branch. It is the core of something that might be useful as another
subcommand to 'git remote' though.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/