Why does git diff-index show intent-to-add file as "Added"?

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

 



Hi,

I have been trying to wrap my head around intent-to-add files to add 
support for them in git-gui and one point really confuses me.

Say I do:

  $ git add -N foo

git-gui uses `git diff-index --cached HEAD` to find out the status of 
the "staged changes" and `git diff-files` to find out the status of 
"unstaged changes".

In this case, running diff-files gives:

  :000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A	foo

which tells git-gui that the file is "added" thanks to the 'A'. Makes 
sense. We can infer that the file in intent-to-add because untracked 
files are not listed by diff-files.

Running diff-index gives:

  :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A	foo

which tells git-gui that the file is added to the index thanks to the 
'A'. This makes less sense. The file has not been staged yet so why 
should it be listed as such?

This causes problems because we then end up showing the file in both the 
"Unstaged Changes" and the "Staged Changes" sections, even though the 
file has no staged changes at all. And `git status` says the same. It 
only lists foo in unstaged changes.

In addition, this makes it much more complicated to determine if a file 
marked as intent-to-add has some parts staged and some others unstaged. 
To determine that, I have to look at what diff-files says about the 
file. If it says 'A', then the file has no changes staged. If it says 
'M' then it does. This means I have to look at the status of the 
"unstaged changes" section to find out information about the "staged 
changes" section. This makes it much harder to write clean, isolated 
routines.

Is there something wrong with the mental model I'm using here? How does 
git-status figure these things out? Or is it really a design mistake? If 
so, what can we do to fix it?

-- 
Regards,
Pratyush Yadav



[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]

  Powered by Linux