All of lore.kernel.org
 help / color / mirror / Atom feed
* How can I tell if a file has been updated upstream?
@ 2010-02-05 16:23 Timur Tabi
  2010-02-05 16:44 ` Shawn O. Pearce
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Timur Tabi @ 2010-02-05 16:23 UTC (permalink / raw)
  To: git

Is there a way for me to tell if a particular file in my repository
has an update in the upstream repository?  For example, the SHA of the
HEAD is different in the remote repository than it is of the HEAD in
the local repository.

The reason I ask is that I have a set of Python scripts that I
distribute via git (other people in the company clone my repository).
I want my script, every time it's run, to check if an update is
available, and ask the user to do "git pull".

-- 
Timur Tabi
Linux kernel developer at Freescale

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

* Re: How can I tell if a file has been updated upstream?
  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 16:50 ` Junio C Hamano
  2010-02-26  0:18 ` Timur Tabi
  2 siblings, 1 reply; 7+ messages in thread
From: Shawn O. Pearce @ 2010-02-05 16:44 UTC (permalink / raw)
  To: Timur Tabi; +Cc: git

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?  For example, the SHA of the
> HEAD is different in the remote repository than it is of the HEAD in
> the local repository.
> 
> The reason I ask is that I have a set of Python scripts that I
> distribute via git (other people in the company clone my repository).
> I want my script, every time it's run, to check if an update is
> available, and ask the user to do "git pull".

You can't tell a particular file, but you could use something like
`git ls-remote refs/heads/master` to see what the branch is at,
and compare that to the last known commit.  If its changed, then
suggest the user do a fetch.

I do this in repo, only I run `git fetch` once per day for the
end-user.  That way the objects are local, and I can use a local
check to see if there are updates that need to be pulled into the
executable working directory.

-- 
Shawn.

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

* Re: How can I tell if a file has been updated upstream?
  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:50 ` Junio C Hamano
  2010-02-05 16:57   ` Timur Tabi
  2010-02-26  0:18 ` Timur Tabi
  2 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2010-02-05 16:50 UTC (permalink / raw)
  To: Timur Tabi; +Cc: git

Timur Tabi <timur@freescale.com> writes:

> The reason I ask is that I have a set of Python scripts that I
> distribute via git (other people in the company clone my repository).
> I want my script, every time it's run, to check if an update is
> available, and ask the user to do "git pull".

So whenever I run your script it calls home, spend a roundtrip time, and
nags me to update?  I don't want to be working with you unless I can go
without running that script less often than once a week ;-)

You need to teach it how to call home.  How do your users "clone"?  Some
over git://, some others over ssh://, yet some others over local
filesystem?  Also how do they run the script?  Directly out of the
repository work tree, or is there a "make install" step involved?

If your users are running from the work tree copy unmodified, then you
would need to look at sys.argv[0] to find out where it is, use that to
find the repository, and using its .git/config learn how the user pulls
from your repository (i.e. git config remote.origin.url), and at the same
time which version it is (i.e. git rev-parse HEAD).  If "make install" is
involved, then you would hardcode the necessary information during the
build process to the script your users would run.

At runtime, you would run "ls-remote HEAD" and compare with the version
you are running.  It may be stale, or it may not be.

How big is the script?  It _might_ be faster to distribute a launcher that
downloads the real script every time it runs and runs that fresh copy that
is guaranteed to be the latest than doing all the hassle of the above.

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

* Re: How can I tell if a file has been updated upstream?
  2010-02-05 16:44 ` Shawn O. Pearce
@ 2010-02-05 16:56   ` Timur Tabi
  2010-02-05 17:39     ` Nicolas Pitre
  0 siblings, 1 reply; 7+ messages in thread
From: Timur Tabi @ 2010-02-05 16:56 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: git

On Fri, Feb 5, 2010 at 10:44 AM, Shawn O. Pearce <spearce@spearce.org> wrote:

> You can't tell a particular file, but you could use something like
> `git ls-remote refs/heads/master` to see what the branch is at,

$ git ls-remote refs/heads/master
fatal: 'refs/heads/master' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

So maybe you meant this:

$ git ls-remote ssh://git.am.freescale.net/git/timur/bin refs/heads/master
20fbe12069038057cbd0d66c5a673956f7792c7d	refs/heads/master

I can use this to compare with the local HEAD.  However, this only
tells me that the repository as a whole has changed.  I was hoping
there would be a way to see if just the one file has change.  I.e. how
can I get the HEAD of a *file* in a remote repository.

> I do this in repo, only I run `git fetch` once per day for the
> end-user.  That way the objects are local, and I can use a local
> check to see if there are updates that need to be pulled into the
> executable working directory.

Yeah, I'm not keen on performing an actual download, even if it's just a fetch.

-- 
Timur Tabi
Linux kernel developer at Freescale

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

* Re: How can I tell if a file has been updated upstream?
  2010-02-05 16:50 ` Junio C Hamano
@ 2010-02-05 16:57   ` Timur Tabi
  0 siblings, 0 replies; 7+ messages in thread
From: Timur Tabi @ 2010-02-05 16:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Fri, Feb 5, 2010 at 10:50 AM, Junio C Hamano <gitster@pobox.com> wrote:

> So whenever I run your script it calls home, spend a roundtrip time, and
> nags me to update?

Yes.  Fortunately, it's all on an internal network, so the overhead is low.

> I don't want to be working with you unless I can go
> without running that script less often than once a week ;-)

That's about how often most people will run the script.

> You need to teach it how to call home.  How do your users "clone"?

git clone git://....

Only I have ssh access to my repository.

> Also how do they run the script?  Directly out of the
> repository work tree, or is there a "make install" step involved?

Directly out of the repository.  It's just a Python script.

> If your users are running from the work tree copy unmodified, then you
> would need to look at sys.argv[0] to find out where it is, use that to
> find the repository, and using its .git/config learn how the user pulls
> from your repository (i.e. git config remote.origin.url), and at the same
> time which version it is (i.e. git rev-parse HEAD).

Ok.

> At runtime, you would run "ls-remote HEAD" and compare with the version
> you are running.  It may be stale, or it may not be.

Ok.

> How big is the script?  It _might_ be faster to distribute a launcher that
> downloads the real script every time it runs and runs that fresh copy that
> is guaranteed to be the latest than doing all the hassle of the above.

I don't want to force an update, and I don't want to have to email
everyone whenever there is an update.   This seems to be the least
intrusive approach.

-- 
Timur Tabi
Linux kernel developer at Freescale

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

* Re: How can I tell if a file has been updated upstream?
  2010-02-05 16:56   ` Timur Tabi
@ 2010-02-05 17:39     ` Nicolas Pitre
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Pitre @ 2010-02-05 17:39 UTC (permalink / raw)
  To: Timur Tabi; +Cc: Shawn O. Pearce, git

On Fri, 5 Feb 2010, Timur Tabi wrote:

> So maybe you meant this:
> 
> $ git ls-remote ssh://git.am.freescale.net/git/timur/bin refs/heads/master
> 20fbe12069038057cbd0d66c5a673956f7792c7d	refs/heads/master
> 
> I can use this to compare with the local HEAD.  However, this only
> tells me that the repository as a whole has changed.  I was hoping
> there would be a way to see if just the one file has change.  I.e. how
> can I get the HEAD of a *file* in a remote repository.

You can't.

You must perform a fetch and then use whatever method to compare with 
origin/master:foobar.py which is the file you're looking for.

> Yeah, I'm not keen on performing an actual download, even if it's just a fetch.

Why?  It is not like if a fetch was terribly more costly than any method 
that could get the version of a file on the remote.


Nicolas

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

* Re: How can I tell if a file has been updated upstream?
  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:50 ` Junio C Hamano
@ 2010-02-26  0:18 ` Timur Tabi
  2 siblings, 0 replies; 7+ messages in thread
From: Timur Tabi @ 2010-02-26  0:18 UTC (permalink / raw)
  To: git

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

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

end of thread, other threads:[~2010-02-26  0:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.