git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How can I tell if a file has been updated upstream?

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 5, 2010, 16:50 UTC
Message-ID
<7vk4urbp9u.fsf@alter.siamese.dyndns.org>
In-Reply-To
<ed82fe3e1002050823gec57827j184c9c4cff4f4a45@mail.gmail.com>
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.

Previous: Nicolas PitreNext: Timur Tabi
Message 5 of 7 in “How can I tell if a file has been updated upstream?”
  1. Timur TabiFeb 5, 2010
  2. Shawn O. PearceFeb 5, 2010
  3. Timur TabiFeb 5, 2010
  4. Nicolas PitreFeb 5, 2010
  5. Junio C HamanoFeb 5, 2010
  6. Timur TabiFeb 5, 2010
  7. Timur TabiFeb 26, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.