{"thread":{"id":"26853","subject":"[RFD] git update-index --remove frotz --add frotz expected behaviour?","startedAt":"2011-03-24T17:07:57Z","lastAt":"2011-03-24T18:28:24Z","messageCount":2,"participants":["Jakob Pfender","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"164238","messageId":"4D8B7A6D.5050801@elegosoft.com","threadId":"26853","inReplyTo":null,"subject":"[RFD] git update-index --remove frotz --add frotz expected behaviour?","fromName":"Jakob Pfender","fromEmail":"jpfender@elegosoft.com","sentAt":"2011-03-24T17:07:57Z","receivedAt":"2011-03-24T17:07:57Z","isPatch":false,"sender":{"key":"jpfender@elegosoft.com","avatar":null},"body":"I'm a bit stumped by update-index' behaviour when calling --remove and \n--add on the same file in that order:\n\n$ touch frotz\n$ git update-index --add frotz\n$ rm frotz\n$ git status -s\nAD frotz\n$ git update-index --remove frotz --add frotz\n$ echo $?\n0\n$ git status -s\n$\n\nNotice that update-index doesn't complain that I'm trying to add a file \nthat doesn't exist, and it's returning with 0.\n\nIs this expected behaviour? Shouldn't I get some sort of error message \ntelling me that I'm trying to add a file I've just removed? Compare:\n\n$ touch xyzzy\n$ git update-index --add xyzzy\n$ rm xyzzy\n$ git update-index --remove xyzzy\n$ git update-index --add xyzzy\nerror: xyzzy: does not exist and --remove not passed\nfatal: Unable to process path xyzzy\n\nCan anyone explain this to me?\n"},{"id":"164247","messageId":"7vy6448jav.fsf@alter.siamese.dyndns.org","threadId":"26853","inReplyTo":"4D8B7A6D.5050801@elegosoft.com","subject":"Re: [RFD] git update-index --remove frotz --add frotz expected behaviour?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-24T18:28:24Z","receivedAt":"2011-03-24T18:28:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakob Pfender <jpfender@elegosoft.com> writes:\n\n> I'm a bit stumped by update-index' behaviour when calling --remove and\n> --add on the same file in that order:\n>\n> $ touch frotz\n> $ git update-index --add frotz\n> $ rm frotz\n> $ git status -s\n> AD frotz\n> $ git update-index --remove frotz --add frotz\n\nThis falls into \"if it hurts, don't do that\" category.  The canonical\norder of command line parameters is to have --options first and then\nrevisions and finally pathspecs.  update-index does not take any revs, so\nyou would be saying \"git update-index --add --remove frotz\".\n\nFor historical reasons, \"update-index\" never adds paths that are not\nalready in the index unless you tell it that it is Ok to do so with\n\"--add\" option.  Also it does not remove without \"--remove\" even after you\nremoved the paths from your working tree.  The important point to note\nhere is that these two options only tell the command it is allowed to add\nor remove the path from the index, and what happens solely depends on what\nyou have in the working tree.\n\nIf you do have Makefile and Rakefile already in the index, and if you only\nhave Makefile and Nakefile in the working tree,\n\n    $ git update-index Nakefile\n\nwill error out because you didn't allow the command to add a new path to\nthe index by giving --add,\n\n    $ git update-index Rakefile\n\nwill error out because you didn't allow the command to remove an existing\npath from the index by giving --remove.  As an obvious consequence:\n\n    $ git update-index --add --remove {M,N,R}akefile\n\nwill reflect the state of these three paths in the working tree to the\nindex.  It won't leave Rakefile in the index _only_ because you don't have\nit in the working tree (and you allowed the command to remove it by giving\nthe --remove option); \"--add\" on the command line is _not_ an instruction\nto \"add\" (implying that the command should error out because it cannot add\nthat which does not exist), it merely is a permission to the command.\n\nAnd this is not going to change.\n"}]}