Subject: Re: Command whose exit code indicates clean or dirty working directory

From: Junio C Hamano <[email-masked]>
Date: Thu, 10 Apr 2025 12:24:26 -0700

Ross Goldberg <[email-masked]> 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".