public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* Command whose exit code indicates clean or dirty working directory
@ 2025-04-10 17:49 Ross Goldberg
  2025-04-10 19:24 ` Junio C Hamano
  2025-04-10 22:11 ` brian m. carlson
  0 siblings, 2 replies; 3+ messages in thread
From: Ross Goldberg @ 2025-04-10 17:49 UTC (permalink / raw)
  To: git@vger.kernel.org


[-- Attachment #1.1.1: Type: text/plain, Size: 530 bytes --]

What is the simplest git command that returns 0 if the working directory is completely clean, or nonzero if it is dirty in any way (staged diff, unstaged diff, file that is both untracked & not ignored, etc.), with nothing printed to stdout or to stderr?
If the simplest such command is complex, is there any feature request to create a simple command, possibly with options that specify what is considered dirty (staged diffs, unstaged diffs, untracked & not ignored, etc.)?

 
 
   Sent from   Proton Mail for iOS

[-- Attachment #1.1.2.1: Type: text/html, Size: 757 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

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

* Re: Command whose exit code indicates clean or dirty working directory
  2025-04-10 17:49 Command whose exit code indicates clean or dirty working directory Ross Goldberg
@ 2025-04-10 19:24 ` Junio C Hamano
  2025-04-10 22:11 ` brian m. carlson
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2025-04-10 19:24 UTC (permalink / raw)
  To: Ross Goldberg; +Cc: git@vger.kernel.org

Ross Goldberg <ross.goldberg@proton.me> writes:

> If the simplest such command is complex, is there any feature request to create a simple
> command, possibly with options that specify what is considered dirty (staged diffs,
> unstaged diffs, untracked & not ignored, etc.)?

With the "possibly with options" part, I doubt there is.  Once you
start having to specify options, you admit that the problem space is
no longer simple.  Depending on occasion, you would be caring
different kind of cleanliness.

If you want to know if there are changes added to the index, "git
diff --cached --quiet" would be a way to ask about it.  If you want
to know if there are changes in the working tree relative to the
index, "git diff --quiet" would be a way to ask about it.  If you
want to know if there are changes in the working tree relative to
the HEAD commit, "git diff --quiet HEAD" would be.  You can use them
to ask about various things you care about, and you can combine
yourself, instead of using a single command with options to specify
which questions to ask.

Having said all that, if what you care the most is simplicity, you
can probably use "git describe --always --dirty", and see if the
output ends with "-dirty" suffix, perhaps?  I suspect that it does
not care about untracked files, which you may have to independently
ask command like "git clean -n".



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

* Re: Command whose exit code indicates clean or dirty working directory
  2025-04-10 17:49 Command whose exit code indicates clean or dirty working directory Ross Goldberg
  2025-04-10 19:24 ` Junio C Hamano
@ 2025-04-10 22:11 ` brian m. carlson
  1 sibling, 0 replies; 3+ messages in thread
From: brian m. carlson @ 2025-04-10 22:11 UTC (permalink / raw)
  To: Ross Goldberg; +Cc: git@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 840 bytes --]

On 2025-04-10 at 17:49:23, Ross Goldberg wrote:
> What is the simplest git command that returns 0 if the working directory is completely clean, or nonzero if it is dirty in any way (staged diff, unstaged diff, file that is both untracked &amp; not ignored, etc.), with nothing printed to stdout or to stderr?
> If the simplest such command is complex, is there any feature request to create a simple command, possibly with options that specify what is considered dirty (staged diffs, unstaged diffs, untracked &amp; not ignored, etc.)?

Here's what I've used:

[ -z "$(git status --porcelain)" ]

That assumes you know the directory is a non-bare working tree.

`git status --porcelain` prints nothing if the working directory is
clean and prints what's dirty otherwise.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

end of thread, other threads:[~2025-04-10 22:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 17:49 Command whose exit code indicates clean or dirty working directory Ross Goldberg
2025-04-10 19:24 ` Junio C Hamano
2025-04-10 22:11 ` brian m. carlson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox