{"thread":{"id":"57575","subject":"crash upon \"commit removedfile/newfile removedfile\"","startedAt":"2022-03-16T20:29:40Z","lastAt":"2022-03-16T21:21:20Z","messageCount":2,"participants":["Yaroslav Halchenko","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"451516","messageId":"YjJECDbAV0DXUTMB@lena.dartmouth.edu","threadId":"57575","inReplyTo":null,"subject":"crash upon \"commit removedfile/newfile removedfile\"","fromName":"Yaroslav Halchenko","fromEmail":"yoh@onerussian.com","sentAt":"2022-03-16T20:09:44Z","receivedAt":"2022-03-16T20:29:40Z","isPatch":false,"sender":{"key":"yoh@onerussian.com","avatar":"https://gravatar.com/avatar/8901b82415ae451a83aea49409708912726e53620e3ac92320bf1f86548d97e9?d=mp&s=160"},"body":"Dear Git Gurus,\n\nOriginally ran into in DANDI project [#127] while using datalad [#6558]\nwhich uses git and git-annex.\n\n\"git commit\" seems to not tolerate well whenever both removed path which became\na directory and a file under that directory  are provided to commit\ninvocation along with the new file path under that directory.  But it is ok\nwhenever removed paths (staged or not) are provided to commit.\n\nA reproducer of the former defect and latter behavior is attached, and\nexecution of it on my laptop provides output pasted in full below, where you\ncan see the \n\n\t+ rm p1\n\t+ mkdir p1\n\t+ touch p1/p2\n\t+ git add p1/p2\n\t+ git commit -m 2 p1/p2 p1\n\terror: 'p1' does not have a commit checked out\n\tfatal: updating files failed\n\nproblematic use case and  git commits just fine whenever removed paths\nprovided in commit invocation:\n\n\t+ rm p2 p3\n\t+ git add p2\n\t+ git commit -m 'removed and even staged one of them' p2 p3\n\t[master 209490a] removed and even staged one of them\n\t 2 files changed, 0 insertions(+), 0 deletions(-)\n\t delete mode 100644 p2\n\t delete mode 100644 p3\n\nI think such inconsistent behavior is a defect in git. Ideally the former  \"git\ncommit -m 2 p1/p2 p1\" shouldn't crash.\n\n\tgit version 2.35.1.473.g83b2b277ed\n\t+ git init\n\tInitialized empty Git repository in /home/yoh/.tmp/git-h0HvnyH/.git/\n\t+ touch p1\n\t+ git add p1\n\t+ git commit -m 1\n\t[master (root-commit) c9e0bff] 1\n\t 1 file changed, 0 insertions(+), 0 deletions(-)\n\t create mode 100644 p1\n\t+ rm p1\n\t+ mkdir p1\n\t+ touch p1/p2\n\t+ git add p1/p2\n\t+ git commit -m 2 p1/p2 p1\n\terror: 'p1' does not have a commit checked out\n\tfatal: updating files failed\n\t+ echo 'that did not work when imho should have!'\n\tthat did not work when imho should have!\n\t+ git commit -m 2 p1/p2\n\t[master 446b8dc] 2\n\t 1 file changed, 0 insertions(+), 0 deletions(-)\n\t rename p1 => p1/p2 (100%)\n\t+ echo 'done -- committed just fine'\n\tdone -- committed just fine\n\t+ touch p2 p3\n\t+ git add p2 p3\n\t+ git commit -m 3 p2 p3\n\t[master 19ffa50] 3\n\t 2 files changed, 0 insertions(+), 0 deletions(-)\n\t create mode 100644 p2\n\t create mode 100644 p3\n\t+ rm p2 p3\n\t+ git add p2\n\t+ git commit -m 'removed and even staged one of them' p2 p3\n\t[master 209490a] removed and even staged one of them\n\t 2 files changed, 0 insertions(+), 0 deletions(-)\n\t delete mode 100644 p2\n\t delete mode 100644 p3\n\t+ echo 'and it worked just fine'\n\n\n[#127] https://github.com/dandi/dandisets/issues/127#issuecomment-1066934910\n[#6558]  DataLad bugreport https://github.com/datalad/datalad/issues/6558\n\n-- \nYaroslav O. Halchenko\nCenter for Open Neuroscience     http://centerforopenneuroscience.org\nDartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755\nPhone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419\nWWW:   http://www.linkedin.com/in/yarik        \n"},{"id":"451520","messageId":"xmqqv8wdk308.fsf@gitster.g","threadId":"57575","inReplyTo":"YjJECDbAV0DXUTMB@lena.dartmouth.edu","subject":"Re: crash upon \"commit removedfile/newfile removedfile\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-16T21:21:11Z","receivedAt":"2022-03-16T21:21:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yaroslav Halchenko <yoh@onerussian.com> writes:\n\n> \t+ rm p1\n> \t+ mkdir p1\n> \t+ touch p1/p2\n> \t+ git add p1/p2\n> \t+ git commit -m 2 p1/p2 p1\n> \terror: 'p1' does not have a commit checked out\n> \tfatal: updating files failed\n\nInteresting.  In this toy example, all the user wants to do is to\nremove p1 and add p1/p2, so an obvious workaround is to just say\n\"git commit\" without any pathspec.  But in real life, there may\nbe cases where the user has already staged more than what the first\ncommit wants to have in the index, and want to limit it to a subset\nby using a pathspec.\n\nI _think_ the response from the command, seeing that the path 'p1'\nthat was previously a file got turned into a directory, is that it\nis guessing that you are trying to replace 'p1' with a submodule,\nbut because 'p1' is not yet a repository, it cannot 'git add' the\ncommit from the 'p1' submodule to include it in the commit.  The\nguess is wrong and it is a bug that it does not notice it---it knows\nthe user added 'p1/p2' to the index, so 'p1' clearly is a mere\nsubdirectory and not a submodule, so it could have known better than\nsaying \"does not have a commit checked out\".\n\nBy the way, program exit with non-zero status, with \"fatal: message\",\nis a controlled error exit, not a crash.  Please reserve the word\n\"crash\" to describe uncontrolled program death.\n\nThanks.\n"}]}