Re: [PATCH] git-prompt.sh: make '+' work for unborn branches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have no clue why git diff --cached isn't used instead of git
diff-index. I was wondering about it, but I decided I don't know
enough about git and there are probably valid reasons for doing it
this way. Though, replacing it with with git diff --cached seems to
have the exact same behaviour, as far as I tested. That would make the
patch a little prettier, as it doesn't contain the empty tree id any
more:

@@ -407,12 +407,11 @@ __git_ps1 ()
         if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
            [ "$(git config --bool bash.showDirtyState)" != "false" ]
         then
-            git diff --no-ext-diff --quiet --exit-code || w="*"
-            if [ -n "$short_sha" ]; then
-                git diff-index --cached --quiet HEAD -- || i="+"
-            else
+            if [ -z "$short_sha" ]; then
                 i="#"
             fi
+            git diff --no-ext-diff --quiet --exit-code || w="*"
+            git diff --no-ext-diff --quiet --exit-code --cached || i="$i+"
         fi
         if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
            [ -r "$g/refs/stash" ]; then


Unfortunately, I don't know much about git diff-files, so I don't know
whether it could be used instead.

In another version I used myself, I indeed used 'git status
--porcelain' and used regexes /^\w/ /^.\w/ and /\?/ on the output. It
seemed to work fine, but it's a bit stupid that it lists all the files
when it could stop almost directly. An
--extremly-short-porcelain-or-whatever-you-would-call-this option that
would just output whether any file is dirty and/or indexed or
something might be useful, though maybe a bit too specific.
(--summarized ?)

-Maurice-


 2014-03-06 21:40 GMT+01:00 Jeff King <peff@xxxxxxxx>:

> On Thu, Mar 06, 2014 at 12:05:24AM +0100, Maurice Bos wrote:
>
> > For unborn branches, it now compares the index against the empty tree.
> > (Just like git status does.)
>
> Sounds sensible, although...
>
> > -                     git diff --no-ext-diff --quiet --exit-code || w="*"
> > -                     if [ -n "$short_sha" ]; then
> > -                             git diff-index --cached --quiet HEAD -- || i="+"
> > -                     else
>
> I notice the old code uses "git diff" immediately above. If we used "git
> diff --cached" here, too, I think it already knows about this empty-tree
> magic.
>
> That being said, it seems odd that we are using "git diff" in the first
> place, and not "git diff-files". This seems to blame all the way back to
> 738a94a, when the functionality was added in the first place. Am I
> missing some reason we can't use diff-files (maybe we want the
> index-refreshing side effect)?
>
> -Peff
>
> PS I thought at first that this could just use "git status --porcelain",
>    which also knows the empty-tree trick.  But that command has no way
>    to quit early on the first change.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]