{"thread":{"id":"63280","subject":"Command whose exit code indicates clean or dirty working directory","startedAt":"2025-04-10T17:49:43Z","lastAt":"2025-04-10T22:11:04Z","messageCount":3,"participants":["Ross Goldberg","Junio C Hamano","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"515964","messageId":"jreR52go49E9pIfAmIdRaoqIgKnVV7uOhR4Mbl9_p2dLG_7mPgO8qsUk7CaWC0nGbJD-2F4nGdQ8X65UtIQ5XOBNQXXzrnHnKbOCLCfEil0=@proton.me","threadId":"63280","inReplyTo":null,"subject":"Command whose exit code indicates clean or dirty working directory","fromName":"Ross Goldberg","fromEmail":"ross.goldberg@proton.me","sentAt":"2025-04-10T17:49:23Z","receivedAt":"2025-04-10T17:49:43Z","isPatch":false,"sender":{"key":"ross.goldberg@proton.me","avatar":null},"body":"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?\nIf 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.)?\n\n \n \n   Sent from   Proton Mail for iOS\n"},{"id":"515967","messageId":"xmqqlds7om51.fsf@gitster.g","threadId":"63280","inReplyTo":"jreR52go49E9pIfAmIdRaoqIgKnVV7uOhR4Mbl9_p2dLG_7mPgO8qsUk7CaWC0nGbJD-2F4nGdQ8X65UtIQ5XOBNQXXzrnHnKbOCLCfEil0=@proton.me","subject":"Re: Command whose exit code indicates clean or dirty working directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-04-10T19:24:26Z","receivedAt":"2025-04-10T19:24:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ross Goldberg <ross.goldberg@proton.me> writes:\n\n> If the simplest such command is complex, is there any feature request to create a simple\n> command, possibly with options that specify what is considered dirty (staged diffs,\n> unstaged diffs, untracked & not ignored, etc.)?\n\nWith the \"possibly with options\" part, I doubt there is.  Once you\nstart having to specify options, you admit that the problem space is\nno longer simple.  Depending on occasion, you would be caring\ndifferent kind of cleanliness.\n\nIf you want to know if there are changes added to the index, \"git\ndiff --cached --quiet\" would be a way to ask about it.  If you want\nto know if there are changes in the working tree relative to the\nindex, \"git diff --quiet\" would be a way to ask about it.  If you\nwant to know if there are changes in the working tree relative to\nthe HEAD commit, \"git diff --quiet HEAD\" would be.  You can use them\nto ask about various things you care about, and you can combine\nyourself, instead of using a single command with options to specify\nwhich questions to ask.\n\nHaving said all that, if what you care the most is simplicity, you\ncan probably use \"git describe --always --dirty\", and see if the\noutput ends with \"-dirty\" suffix, perhaps?  I suspect that it does\nnot care about untracked files, which you may have to independently\nask command like \"git clean -n\".\n\n\n"},{"id":"515971","messageId":"Z_hB9gZL6FE7PezC@tapette.crustytoothpaste.net","threadId":"63280","inReplyTo":"jreR52go49E9pIfAmIdRaoqIgKnVV7uOhR4Mbl9_p2dLG_7mPgO8qsUk7CaWC0nGbJD-2F4nGdQ8X65UtIQ5XOBNQXXzrnHnKbOCLCfEil0=@proton.me","subject":"Re: Command whose exit code indicates clean or dirty working directory","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-04-10T22:11:02Z","receivedAt":"2025-04-10T22:11:04Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-04-10 at 17:49:23, Ross Goldberg wrote:\n> 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?\n> 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.)?\n\nHere's what I've used:\n\n[ -z \"$(git status --porcelain)\" ]\n\nThat assumes you know the directory is a non-bare working tree.\n\n`git status --porcelain` prints nothing if the working directory is\nclean and prints what's dirty otherwise.\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"}]}