{"thread":{"id":"36069","subject":"[PATCH] git-prompt.sh: make '+' work for unborn branches","startedAt":"2014-03-05T23:05:24Z","lastAt":"2014-03-27T23:08:11Z","messageCount":3,"participants":["Maurice Bos","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"236142","messageId":"20140305233219.A6FF54284F@server","threadId":"36069","inReplyTo":null,"subject":"[PATCH] git-prompt.sh: make '+' work for unborn branches","fromName":"Maurice Bos","fromEmail":"m-ou.se@m-ou.se","sentAt":"2014-03-05T23:05:24Z","receivedAt":"2014-03-05T23:05:24Z","isPatch":true,"sender":{"key":"m-ou.se@m-ou.se","avatar":null},"body":"For unborn branches, it now compares the index against the empty tree.\n(Just like git status does.)\n\nSigned-off-by: Maurice Bos <m-ou.se@m-ou.se>\n---\n contrib/completion/git-prompt.sh | 10 ++++++----\n 1 file changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 7b732d2..f656838 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -407,12 +407,14 @@ __git_ps1 ()\n \t\tif [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ] &&\n \t\t   [ \"$(git config --bool bash.showDirtyState)\" != \"false\" ]\n \t\tthen\n-\t\t\tgit diff --no-ext-diff --quiet --exit-code || w=\"*\"\n-\t\t\tif [ -n \"$short_sha\" ]; then\n-\t\t\t\tgit diff-index --cached --quiet HEAD -- || i=\"+\"\n-\t\t\telse\n+\t\t\tlocal treeish=HEAD\n+\t\t\tif [ -z \"$short_sha\" ]; then\n \t\t\t\ti=\"#\"\n+\t\t\t\t# the empty tree\n+\t\t\t\ttreeish=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n \t\t\tfi\n+\t\t\tgit diff --no-ext-diff --quiet --exit-code || w=\"*\"\n+\t\t\tgit diff-index --cached --quiet $treeish -- || i=\"$i+\"\n \t\tfi\n \t\tif [ -n \"${GIT_PS1_SHOWSTASHSTATE-}\" ] &&\n \t\t   [ -r \"$g/refs/stash\" ]; then\n-- \n1.8.5.rc0.23.gaa27064\n"},{"id":"236201","messageId":"CABbCQwsKFWjk1Nzc9jmpyNdbXC+mOf5qfNg77PoiXrUOmrq6uA@mail.gmail.com","threadId":"36069","inReplyTo":"CABbCQwskqZzzRXm5K3dnOfRoAcx8jpsdskngmN7f1EvY6BONgw@mail.gmail.com","subject":"Re: [PATCH] git-prompt.sh: make '+' work for unborn branches","fromName":"Maurice Bos","fromEmail":"m-ou.se@m-ou.se","sentAt":"2014-03-06T21:19:43Z","receivedAt":"2014-03-06T21:19:43Z","isPatch":true,"sender":{"key":"m-ou.se@m-ou.se","avatar":null},"body":"I have no clue why git diff --cached isn't used instead of git\ndiff-index. I was wondering about it, but I decided I don't know\nenough about git and there are probably valid reasons for doing it\nthis way. Though, replacing it with with git diff --cached seems to\nhave the exact same behaviour, as far as I tested. That would make the\npatch a little prettier, as it doesn't contain the empty tree id any\nmore:\n\n@@ -407,12 +407,11 @@ __git_ps1 ()\n         if [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ] &&\n            [ \"$(git config --bool bash.showDirtyState)\" != \"false\" ]\n         then\n-            git diff --no-ext-diff --quiet --exit-code || w=\"*\"\n-            if [ -n \"$short_sha\" ]; then\n-                git diff-index --cached --quiet HEAD -- || i=\"+\"\n-            else\n+            if [ -z \"$short_sha\" ]; then\n                 i=\"#\"\n             fi\n+            git diff --no-ext-diff --quiet --exit-code || w=\"*\"\n+            git diff --no-ext-diff --quiet --exit-code --cached || i=\"$i+\"\n         fi\n         if [ -n \"${GIT_PS1_SHOWSTASHSTATE-}\" ] &&\n            [ -r \"$g/refs/stash\" ]; then\n\n\nUnfortunately, I don't know much about git diff-files, so I don't know\nwhether it could be used instead.\n\nIn another version I used myself, I indeed used 'git status\n--porcelain' and used regexes /^\\w/ /^.\\w/ and /\\?/ on the output. It\nseemed to work fine, but it's a bit stupid that it lists all the files\nwhen it could stop almost directly. An\n--extremly-short-porcelain-or-whatever-you-would-call-this option that\nwould just output whether any file is dirty and/or indexed or\nsomething might be useful, though maybe a bit too specific.\n(--summarized ?)\n\n-Maurice-\n\n\n 2014-03-06 21:40 GMT+01:00 Jeff King <peff@peff.net>:\n\n> On Thu, Mar 06, 2014 at 12:05:24AM +0100, Maurice Bos wrote:\n>\n> > For unborn branches, it now compares the index against the empty tree.\n> > (Just like git status does.)\n>\n> Sounds sensible, although...\n>\n> > -                     git diff --no-ext-diff --quiet --exit-code || w=\"*\"\n> > -                     if [ -n \"$short_sha\" ]; then\n> > -                             git diff-index --cached --quiet HEAD -- || i=\"+\"\n> > -                     else\n>\n> I notice the old code uses \"git diff\" immediately above. If we used \"git\n> diff --cached\" here, too, I think it already knows about this empty-tree\n> magic.\n>\n> That being said, it seems odd that we are using \"git diff\" in the first\n> place, and not \"git diff-files\". This seems to blame all the way back to\n> 738a94a, when the functionality was added in the first place. Am I\n> missing some reason we can't use diff-files (maybe we want the\n> index-refreshing side effect)?\n>\n> -Peff\n>\n> PS I thought at first that this could just use \"git status --porcelain\",\n>    which also knows the empty-tree trick.  But that command has no way\n>    to quit early on the first change.\n"},{"id":"237955","messageId":"20140327230811.GD32434@sigill.intra.peff.net","threadId":"36069","inReplyTo":"CABbCQwskqZzzRXm5K3dnOfRoAcx8jpsdskngmN7f1EvY6BONgw@mail.gmail.com","subject":"Re: [PATCH] git-prompt.sh: make '+' work for unborn branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-03-27T23:08:11Z","receivedAt":"2014-03-27T23:08:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 06, 2014 at 10:16:47PM +0100, Maurice Bos wrote:\n\n> I have no clue why git diff --cached isn't used instead of git diff-index.\n> I was wondering about it, but I decided I don't know enough about git and\n> there are probably valid reasons for doing it this way. Though, replacing\n> it with with git diff --cached seems to have the exact same behaviour, as\n> far as I tested. That would make the patch a little prettier, as it doesn't\n> contain the empty tree id any more:\n\nI think it probably goes in the wrong direction, though. The prompt code\nshould probably be building on plumbing, not porcelain. So your original\npatch as-is is probably the most sensible thing (we may want to convert\nthe first git-diff call to use plumbing, too, but that would be a\nseparate patch).\n\nIt looks like Junio did not pick up your patch. You may want to repost\nit.\n\n-Peff\n"}]}