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

Re: git-pull (or cg-fetch?) with exit status

From
Junio C Hamano <junkio@cox.net>
Date
Oct 30, 2005, 17:19 UTC
Message-ID
<7v3bmiudl1.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<86fyqjt9w9.fsf@blue.stonehenge.com>
merlyn@stonehenge.com (Randal L. Schwartz) writes:
Show 6 quoted lines
> Other than grep the output of the "pull" commands, I'd like to have a
> flag added that will also set an exit status to "successful" if new
> things were pulled.  That way, I can automate a "make install"
> resulting from a successful new pull, ala:
>
>         git-pull --silent && make install
How about this instead of your one-liner?
	old_head=$(git-rev-parse --verify HEAD) &&
        git-pull -n >/dev/null 2>&1 || exit
        new_head=$(git-rev-parse --verify HEAD)
	test "$old_head" = "$new_head" || make test install

git-pull has at least 4 different possible outcomes, and its exit code talks about its success/failure right now.

 1. fetch did not succeed, so pull should result in failure. In
    this case there is no change in your repository, and no
    point rebuilding.
 2. fetch contacted the other end and concluded conversation
    correctly.
    2-a. There was no change upstream (or you were up-to-date --
         the other side was behind you).  This is a successful
         pull, but you probably do not want to rebuild.
    2-b. There were changes upstream and we tried to merge.
         Merge was successful.  This case you would want to
         rebuild.
    2-c. There were changes upstream and automerge failed.  You
         cannot rebuild in this case.

With your proposal we should need to exit non-zero in case 2-a when we are running with --silent. This feels somewhat counter-intuitive if not wrong, even if it is only done under a particular flag.

Previous: Randal L. SchwartzNext: Randal L. Schwartz
Message 2 of 3 in “git-pull (or cg-fetch?) with exit status”
  1. Randal L. SchwartzOct 30, 2005
  2. Junio C HamanoOct 30, 2005
  3. Randal L. SchwartzOct 30, 2005

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.