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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 10, 2025, 19:24 UTC
Message-ID
<xmqqlds7om51.fsf@gitster.g>
In-Reply-To
<jreR52go49E9pIfAmIdRaoqIgKnVV7uOhR4Mbl9_p2dLG_7mPgO8qsUk7CaWC0nGbJD-2F4nGdQ8X65UtIQ5XOBNQXXzrnHnKbOCLCfEil0=@proton.me>
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".

Previous: Ross GoldbergNext: brian m. carlson
Message 2 of 3 in “Command whose exit code indicates clean or dirty working directory”
  1. Ross GoldbergApr 10, 2025
  2. Junio C HamanoApr 10, 2025
  3. brian m. carlsonApr 10, 2025

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.