threads / discuss / 36336

git-status -- trying to understand all possible states

Subject: git-status -- trying to understand all possible states

## tl;dr

5 messages between Apr 1, 2014 and Apr 2, 2014.

replies: 4people: 4as markdown or json

Michael Toy· Apr 1, 2014, 20:07 UTC · lore
I also have this question posted to stack overflow ( http://stackoverflow.com/questions/22792906/how-do-i-produce-every-possible-git-status ), but perhaps this is a better place to ask this question.
In working on some code which provides an interface to existing git repositories the question I had was "what actions should I present to a user", which lead to the question, "what does a user need to do to generate that condition", which lead to developing this gist:
https://gist.github.com/the-michael-toy/9907309
... which is a ruby script which tries to produce a repository with a file in every possible "git-status" XY condition
Of the 24 possibilities (not counting ignored) in git-status, there are 7 that I can't figure out how to generate.

D M deleted from index C [ MD] copied in index D D unmerged, both deleted A U unmerged, added by us U A unmerged, added by them

any clues, including pointers to "just go read XXX" would be appreciated.
Junio C Hamano· Apr 1, 2014, 21:37 UTC · re: Michael Toy · lore

Re: git-status -- trying to understand all possible states

Michael Toy <michael@toyland.org> writes:
> Of the 24 possibilities (not counting ignored) in git-status,
> there are 7 that I can't figure out how to generate.

As the post [*1*] that triggered e92e9cd3 (Documentation improvements for the description of short format., 2010-04-23), which is where the bulk of the format description comes from, says, this is "Patches welcome" ;-) Some are just covering possible permutations and it is not surprising if they would not appear in practice.

> D           M    deleted from index

I doubt this is possible in practice; once you do not have the entry in the index, we do not even look at the working tree file, so it would be unusual to see M in the second column.

> D           D    unmerged, both deleted
> A           U    unmerged, added by us
> U           A    unmerged, added by them
    $ x="100644 $(git hash-object --stdin </dev/null)" &&
      printf "$x 2\tbar\n$x 1\tfoo\n$x 3\tbaz" |
      git update-index --index-info
    $ git status --short -suno
    AU bar
    UA baz
    DD foo
    $ git ls-files -u
    100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 2       bar
    100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 3       baz
    100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 1       foo

When you are using higher-level machinery to merge, "we added, they left it missing" (i.e. bar that has only stage #2) is automatically resolved to an addition by the trivial merge machinery. The "they added, we left it missing" (i.e. baz with only stage #3) case is identical. Also "both of us removed" (i.e. foo that has only stage #1) is resolved to a deletion by the trivial merge machinery. Hence you would not see these three unless you are developing Git using a low-level plumbing machinery.

[Reference]
*1* http://thread.gmane.org/gmane.comp.version-control.git/144455/focus=144468
Michael Toy· Apr 1, 2014, 23:01 UTC · re: Junio C Hamano · lore

Re: git-status -- trying to understand all possible states

On Apr 1, 2014, at 2:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
>> D           M    deleted from index
> 
> I doubt this is possible in practice ...
> 
>> D           D    unmerged, both deleted
>> A           U    unmerged, added by us
>> U           A    unmerged, added by them
> 
>   ... you would not see these three unless you are developing Git using a
> low-level plumbing machinery.
Thanks, that is very helpful.
The "C[ MD]" are now the remaining mystery
Jonathan Nieder· Apr 1, 2014, 22:20 UTC · re: Michael Toy · lore

Re: git-status -- trying to understand all possible states

Michael Toy wrote:
> https://gist.github.com/the-michael-toy/9907309
Two nits:
 - Please use --porcelain (implied by -z in the absence of another
   format option) instead of --short.  --short is meant to be human
   readable and details of the output might change some day.
 - Depending on what you're trying to do, you might find the output
   from other commands such as "git ls-files -s" or "git diff-files"
   easier to work with.

Hope that helps, Jonathan

Matthieu Moy· Apr 2, 2014, 08:31 UTC · re: Jonathan Nieder · lore

Re: git-status -- trying to understand all possible states

Jonathan Nieder <jrnieder@gmail.com> writes:
>  - Please use --porcelain (implied by -z in the absence of another
>    format option) instead of --short.  --short is meant to be human
>    readable and details of the output might change some day.
It already does: part of the output may be translated to non-english.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads