git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Haber <mh+git@zugschlus.de>
To: git@vger.kernel.org
Subject: Re: How to check repository/working tree status from a script
Date: Wed, 20 May 2009 13:10:28 +0200	[thread overview]
Message-ID: <20090520111028.GA15453@torres.zugschlus.de> (raw)
In-Reply-To: <alpine.LFD.2.01.0905190915050.3301@localhost.localdomain>

On Tue, May 19, 2009 at 09:18:12AM -0700, Linus Torvalds wrote:
> On Tue, 19 May 2009, Marc Haber wrote:
> > On Tue, May 19, 2009 at 04:34:47PM +0100, Tony Finch wrote:
> > > On Tue, 19 May 2009, Marc Haber wrote:
> > > > I would like to check in a script whether there (a) are uncommitted
> > > > changes (as in "working tree differs from local repository")
> > > 
> > > # check working tree is not different from the index
> > > git diff --quiet
> > > # check that the index is not different from the head
> > > git diff --quiet --cached
> > 
> > $ git diff --quiet; echo $?
> > 0
> > $ git diff --quiet --cached; echo $?
> > 0
> > $ touch keks
> > $ git diff --quiet; echo $?
> > 0
> > $ git diff --quiet --cached; echo $?
> > 0
> > $
> > 
> > Am I missing something?
> 
> If "keks" is already something you know about, then 'touch' wouldn't have 
> changed it, so diff won't show it.

keks didn't exist previously, so the touch generated a new empty 0 byte
file.

> And if what you want to know about is whether there are _new_ files you 
> might want to check, then you need a third check: 'git ls-files'. You 
> won't see it in the error code, but you can do
> 
> 	others=$(git ls-files -o --exclude-standard)
> 
> and then check it 'others' is empty or not.

So parsing the output is both the canonical and only way to do so
since there is no meaningful exit code? Can I assume that the
formatting of git output is not subject to change?

Greetings
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Mannheim, Germany  |  lose things."    Winona Ryder | Fon: *49 621 72739834
Nordisch by Nature |  How to make an American Quilt | Fax: *49 3221 2323190

  parent reply	other threads:[~2009-05-20 11:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-19 14:35 How to check repository/working tree status from a script Marc Haber
2009-05-19 15:34 ` Tony Finch
2009-05-19 16:00   ` Marc Haber
2009-05-19 16:16     ` Tony Finch
2009-05-20 14:28       ` Marc Haber
2009-05-19 16:18     ` Linus Torvalds
2009-05-19 16:29       ` Linus Torvalds
2009-05-20 14:27         ` Marc Haber
2009-05-20 11:10       ` Marc Haber [this message]
2009-05-20 11:19         ` Santi Béjar
2009-05-20 11:32         ` Johannes Sixt
2009-05-20 14:29           ` Marc Haber
2009-05-21 13:24 ` Marc Haber
2009-05-21 15:37   ` Jeff King
2009-05-23 20:39     ` Marc Haber

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=20090520111028.GA15453@torres.zugschlus.de \
    --to=mh+git@zugschlus.de \
    --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).