{"thread":{"id":"21467","subject":"determine if the tree is dirty","startedAt":"2009-11-03T18:57:37Z","lastAt":"2009-11-03T21:07:19Z","messageCount":5,"participants":["Adam Mercer","Jeff Epler","Junio C Hamano","Markus Hitter"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"126666","messageId":"799406d60911031057l5dcb4d4fi3705cc66997ff7f7@mail.gmail.com","threadId":"21467","inReplyTo":null,"subject":"determine if the tree is dirty","fromName":"Adam Mercer","fromEmail":"ramercer@gmail.com","sentAt":"2009-11-03T18:57:37Z","receivedAt":"2009-11-03T18:57:37Z","isPatch":false,"sender":{"key":"ramercer@gmail.com","avatar":"https://gravatar.com/avatar/16dc719817f62b75075d529ce4ea992ee82bb1a08e45a3029797f39223d6ee64?d=mp&s=160"},"body":"Hi\n\nAs part of a python script I need to determine if a tree has any\nuncommitted changes, so far I am been using:\n\n  # determine tree status\n  status_cmd = 'git status'\n  status_output = run_external_command(status_cmd,\nhonour_ret_code=False)[1].strip()\n  if status_output.endswith('no changes added to commit (use \"git add\"\nand/or \"git commit -a\")'):\n    git_status = 'UNCLEAN: Some modifications not committed'\n  else:\n    git_status = 'CLEAN: All modifications committed'\n\nbut I feel that this relies to heavily on the porcelain and that there\nshould be a better way to accomplish this without relying on parsing\nthe output of git-status.\n\nDoes anyone know of a better way to accomplish this?\n\nCheers\n\nAdam\n"},{"id":"126667","messageId":"20091103190619.GC30171@unpythonic.net","threadId":"21467","inReplyTo":"799406d60911031057l5dcb4d4fi3705cc66997ff7f7@mail.gmail.com","subject":"Re: determine if the tree is dirty","fromName":"Jeff Epler","fromEmail":"jepler@unpythonic.net","sentAt":"2009-11-03T19:06:19Z","receivedAt":"2009-11-03T19:06:19Z","isPatch":false,"sender":{"key":"jepler@unpythonic.net","avatar":"https://avatars.githubusercontent.com/u/1517291?v=4"},"body":"On Tue, Nov 03, 2009 at 12:57:37PM -0600, Adam Mercer wrote:\n> As part of a python script I need to determine if a tree has any\n> uncommitted changes\n\nGIT-VERSION-GEN uses something like this (shell script):\n        git update-index -q --refresh\n        test -z \"$(git diff-index --name-only HEAD --)\" || VN=\"$VN-dirty\" ;;\n\nJeff\n"},{"id":"126668","messageId":"7v3a4vs9g3.fsf@alter.siamese.dyndns.org","threadId":"21467","inReplyTo":"799406d60911031057l5dcb4d4fi3705cc66997ff7f7@mail.gmail.com","subject":"Re: determine if the tree is dirty","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-03T19:19:08Z","receivedAt":"2009-11-03T19:19:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adam Mercer <ramercer@gmail.com> writes:\n\n> As part of a python script I need to determine if a tree has any\n> uncommitted changes, so far I am been using:\n>\n>   # determine tree status\n>   status_cmd = 'git status'\n>   status_output = run_external_command(status_cmd,\n> honour_ret_code=False)[1].strip()\n>   if status_output.endswith('no changes added to commit (use \"git add\"\n> and/or \"git commit -a\")'):\n>     git_status = 'UNCLEAN: Some modifications not committed'\n>   else:\n>     git_status = 'CLEAN: All modifications committed'\n>\n> but I feel that this relies to heavily on the porcelain and that there\n> should be a better way to accomplish this without relying on parsing\n> the output of git-status.\n>\n> Does anyone know of a better way to accomplish this?\n\nUse plumbing commands.\n\n\"git diff-files\" will show changes you have in the work tree compared to\nthe index.\n\n\"git diff-index HEAD\" will show changes you have in the work tree compared\nto the HEAD.\n\n\"git diff-index --cached HEAD\" will show changes you have in the index\ncompared to the HEAD.\n"},{"id":"126669","messageId":"799406d60911031130u3e37677fi1a8dfd6f7fdfdfe9@mail.gmail.com","threadId":"21467","inReplyTo":"7v3a4vs9g3.fsf@alter.siamese.dyndns.org","subject":"Re: determine if the tree is dirty","fromName":"Adam Mercer","fromEmail":"ramercer@gmail.com","sentAt":"2009-11-03T19:30:02Z","receivedAt":"2009-11-03T19:30:02Z","isPatch":false,"sender":{"key":"ramercer@gmail.com","avatar":"https://gravatar.com/avatar/16dc719817f62b75075d529ce4ea992ee82bb1a08e45a3029797f39223d6ee64?d=mp&s=160"},"body":"On Tue, Nov 3, 2009 at 13:06, Jeff Epler <jepler@unpythonic.net> wrote:\n\n> GIT-VERSION-GEN uses something like this (shell script):\n>        git update-index -q --refresh\n>        test -z \"$(git diff-index --name-only HEAD --)\" || VN=\"$VN-dirty\" ;;\n\nOn Tue, Nov 3, 2009 at 13:19, Junio C Hamano <gitster@pobox.com> wrote:\n\n> Use plumbing commands.\n>\n> \"git diff-files\" will show changes you have in the work tree compared to\n> the index.\n>\n> \"git diff-index HEAD\" will show changes you have in the work tree compared\n> to the HEAD.\n>\n> \"git diff-index --cached HEAD\" will show changes you have in the index\n> compared to the HEAD.\n\nFantastic, this is exactly what I was after! Thanks!\n\nCheers\n\nAdam\n"},{"id":"126674","messageId":"83B75882-0005-4BB3-BA7C-60A9105BDD5A@jump-ing.de","threadId":"21467","inReplyTo":"799406d60911031057l5dcb4d4fi3705cc66997ff7f7@mail.gmail.com","subject":"Re: determine if the tree is dirty","fromName":"Markus Hitter","fromEmail":"mah@jump-ing.de","sentAt":"2009-11-03T21:07:19Z","receivedAt":"2009-11-03T21:07:19Z","isPatch":false,"sender":{"key":"mah@jump-ing.de","avatar":"https://avatars.githubusercontent.com/u/318581?v=4"},"body":"\nAm 03.11.2009 um 19:57 schrieb Adam Mercer:\n\n> As part of a python script I need to determine if a tree has any\n> uncommitted changes, so far I am been using:\n> [...]\n> Does anyone know of a better way to accomplish this?\n\nI'm using\n\ngit ls-files -m -o -d --exclude-standard\n\nIf it returns anything, your repo is dirty.\n\n\nMarkus\n\n- - - - - - - - - - - - - - - - - - -\nDipl. Ing. Markus Hitter\nhttp://www.jump-ing.de/\n"}]}