From: Timur Tabi <timur@freescale.com>
To: git <git@vger.kernel.org>
Subject: Re: How can I tell if a file has been updated upstream?
Date: Thu, 25 Feb 2010 18:18:51 -0600 [thread overview]
Message-ID: <ed82fe3e1002251618g750764bm82b0653770554dcf@mail.gmail.com> (raw)
In-Reply-To: <ed82fe3e1002050823gec57827j184c9c4cff4f4a45@mail.gmail.com>
On Fri, Feb 5, 2010 at 10:23 AM, Timur Tabi <timur@freescale.com> wrote:
> Is there a way for me to tell if a particular file in my repository
> has an update in the upstream repository?
Thanks to everyone who replied. Here's what I came up with:
def check_for_updates():
# Get the path to our script. This should be a git repository.
script_path = os.path.dirname(os.path.realpath(__file__))
# Determine the upstream URL
p = subprocess.Popen(['git', 'config', '-f', script_path + '/.git/config',
'--get', 'remote.origin.url'],
shell=False, stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'))
url = p.communicate()[0].strip()
if not url:
# The script is not running from a git repository
return
# Determine the HEAD of the upstream repository
p = subprocess.Popen(['git', 'ls-remote', url, 'HEAD'],
shell=False, stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'))
sha = p.communicate()[0].split()
if not sha:
# Something is wrong with the upstream repository
return
sha = sha[0] # The SHA of the upstream head
# Check if the remote SHA is in the local repository.
# git --git-dir=/home/b04825/bin/.git show-ref HEAD
p = subprocess.Popen(['git', '--git-dir=' + script_path + '/.git',
'log', '-1', sha],
shell=False, stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'))
if not p.communicate()[0]:
# If we can't find the SHA locally, then it means that the local
# repository is out of date. We pretend that it means that this script
# is out of date.
print 'There is an update for this script available. Please
pull from the remote'
print 'repository (e.g. "cd %s; git pull")' % script_path
--
Timur Tabi
Linux kernel developer at Freescale
prev parent reply other threads:[~2010-02-26 0:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-05 16:23 How can I tell if a file has been updated upstream? Timur Tabi
2010-02-05 16:44 ` Shawn O. Pearce
2010-02-05 16:56 ` Timur Tabi
2010-02-05 17:39 ` Nicolas Pitre
2010-02-05 16:50 ` Junio C Hamano
2010-02-05 16:57 ` Timur Tabi
2010-02-26 0:18 ` Timur Tabi [this message]
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=ed82fe3e1002251618g750764bm82b0653770554dcf@mail.gmail.com \
--to=timur@freescale.com \
--cc=git@vger.kernel.org \
/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).