Re: git-add fails after file type change
From: Junio C Hamano <hidden>
Date: 2016-08-11 19:43:35
Steven Grimm [off-list ref] writes:
A Large Angry SCM wrote:quoted
Did you try "git-update-index --replace dir"?Turns out that doesn't work. It gives me the same error I get without the --replace option: error: dir: cannot add to the index - missing --add option? fatal: Unable to process file dir
"update-index --replace --add" would be the way.
$ git ls-files -s
100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0 1/2
100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 3
$ ls -F
./ ../ 1/ 3 .git/
There is file 1/2 in directory 1.
$ mv 1 tmp ; mv 3 1 ; mv tmp 3
$ ls -F
./ ../ 1 3/ .git/
I just swapped them.
$ git update-index --replace --add 1
$ git ls-files -s
100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 1
100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 3
You are allowing update-index to 'add' things so you would need
to say --add regardless of --replace (--replace is only to allow
removal of conflicting entries while adding). In the hindsight,
we could have implied --add with --replace, but that is the way
it is, and update-index is not a Porcelain so there is not much
point fixing it now.
But I think you helped me to spot a bug ;-).
$ git update-index --replace --add 3/2
$ git ls-files -s
100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 1
100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 3
100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0 3/2
The entry '3' should have been removed when we did --replace.
This index cannot be written out as a tree:
$ git write-tree
You have both 3 and 3/2
fatal: git-write-tree: error building trees
Currently we need to remove '3' by hand X-<.
$ git update-index --remove 3
$ git ls-files -s
100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 1
100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0 3/2
$ git write-tree
77be0dd800d74913a90662e35215ee648815fc17