{"thread":{"id":"59068","subject":"Misleading error message on a failed `git mv`","startedAt":"2023-01-11T04:19:48Z","lastAt":"2023-01-11T23:25:56Z","messageCount":4,"participants":["Arthur Milchior","Jeff King","Torsten Bögershausen","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"470086","messageId":"CAEcbrFc=R=3aEwEE56EvZSPSV4+RWFxt=hm7csZ7oBTR8BDQzA@mail.gmail.com","threadId":"59068","inReplyTo":null,"subject":"Misleading error message on a failed `git mv`","fromName":"Arthur Milchior","fromEmail":"arthur.milchior@gmail.com","sentAt":"2023-01-11T04:19:29Z","receivedAt":"2023-01-11T04:19:48Z","isPatch":false,"sender":{"key":"arthur.milchior@gmail.com","avatar":null},"body":"Thanks for git, and happy new year.\nHere is what I believe to be a bug in an error message\n\nThank you for filling out a Git bug report!\n\nPlease answer the following questions to help us understand your issue.\n\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\ngit init\n\ntouch file\n\ngit add file\n\ngit mv file folder/file\n\n\nWhat did you expect to happen? (Expected behavior)\n\nEither creating folder, or stating that folder does not exists\n\n\nWhat happened instead? (Actual behavior)\n\nError message is\n\nfatal: renaming 'file' failed: No such file or directory\n\n\nWhat's different between what you expected and what actually happened?\n\nThe error message seems to indicate that file does not exists. It\nactually exists. The destination directory does not exists and is the\none that should be mentionned.\n\n\nAnything else you want to add:\n\n\nPlease review the rest of the bug report below.\n\nYou can delete any lines you don't wish to share.\n\n\n\n[System Info]\n\ngit version:\n\ngit version 2.39.0.314.g84b9a713c41-goog\n\ncpu: x86_64\n\nno commit associated with this build\n\nsizeof-long: 8\n\nsizeof-size_t: 8\n\nshell-path: /bin/sh\n\nfeature: fsmonitor--daemon\n\nuname: Darwin 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51\nPST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 x86_64\n\ncompiler info: clang: 13.1.6 (clang-1316.0.21.2.5)\n\nlibc info: no libc information available\n\n$SHELL (typically, interactive shell): /bin/bash\n\n\n\n[Enabled Hooks]\n\nRegards,\nArthur\n"},{"id":"470100","messageId":"Y78I5E/BCr1QQ6aL@coredump.intra.peff.net","threadId":"59068","inReplyTo":"CAEcbrFc=R=3aEwEE56EvZSPSV4+RWFxt=hm7csZ7oBTR8BDQzA@mail.gmail.com","subject":"Re: Misleading error message on a failed `git mv`","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-01-11T19:07:16Z","receivedAt":"2023-01-11T19:07:29Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 11, 2023 at 05:19:29AM +0100, Arthur Milchior wrote:\n\n> Error message is\n> \n> fatal: renaming 'file' failed: No such file or directory\n> \n> \n> What's different between what you expected and what actually happened?\n> \n> The error message seems to indicate that file does not exists. It\n> actually exists. The destination directory does not exists and is the\n> one that should be mentionned.\n\nI agree the message is not specific as to which case happened, but this\nis all we get from the kernel's error reporting. We called rename(), the\nsyscall returned ENOENT, and we fed that to strerror() to get \"No such\nfile or directory\". From the manpage for rename(2):\n\n  ENOENT The link named by oldpath does not exist; or, a directory\n\t component in newpath does not exist; or, oldpath or newpath is\n\t an empty string.\n\nIf we wanted to be more specific, we'd have to go to extra work to\ndiagnose each case. Most tools don't bother. For example:\n\n  $ touch foo\n  $ mv foo bar/foo\n  mv: cannot move 'foo' to 'bar/foo': No such file or directory\n\nIt's quirky, for sure, but it's how most Unix tools behave here.\n\n-Peff\n"},{"id":"470108","messageId":"20230111214337.ybrmiyeius5xzalf@tb-raspi4","threadId":"59068","inReplyTo":"Y78I5E/BCr1QQ6aL@coredump.intra.peff.net","subject":"Re: Misleading error message on a failed `git mv`","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2023-01-11T21:43:37Z","receivedAt":"2023-01-11T21:49:02Z","isPatch":false,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Wed, Jan 11, 2023 at 02:07:16PM -0500, Jeff King wrote:\n> On Wed, Jan 11, 2023 at 05:19:29AM +0100, Arthur Milchior wrote:\n>\n> > Error message is\n> >\n> > fatal: renaming 'file' failed: No such file or directory\n> >\n> >\n> > What's different between what you expected and what actually happened?\n> >\n> > The error message seems to indicate that file does not exists. It\n> > actually exists. The destination directory does not exists and is the\n> > one that should be mentionned.\n>\n> I agree the message is not specific as to which case happened, but this\n> is all we get from the kernel's error reporting. We called rename(), the\n> syscall returned ENOENT, and we fed that to strerror() to get \"No such\n> file or directory\". From the manpage for rename(2):\n>\n>   ENOENT The link named by oldpath does not exist; or, a directory\n> \t component in newpath does not exist; or, oldpath or newpath is\n> \t an empty string.\n>\n> If we wanted to be more specific, we'd have to go to extra work to\n> diagnose each case. Most tools don't bother. For example:\n>\n>   $ touch foo\n>   $ mv foo bar/foo\n>   mv: cannot move 'foo' to 'bar/foo': No such file or directory\n>\n> It's quirky, for sure, but it's how most Unix tools behave here.\n>\n> -Peff\n\nWe may be able to inform the user that the destination is the problem,\nand not the source.\nIs this worth to do the following ?\nAny thoughts ?\n\n\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 19790ce38f..58e24889c0 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -452,8 +452,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tif (!(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) &&\n \t\t    !(dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&\n \t\t    rename(src, dst) < 0) {\n+\t\t\tstruct stat st;\n \t\t\tif (ignore_errors)\n \t\t\t\tcontinue;\n+\t\t\tif (!lstat(src, &st)) {\n+\t\t\t\tdie_errno(_(\"moving '%s' into destination '%s' failed\"), src, dst);\n+\t\t\t}\n \t\t\tdie_errno(_(\"renaming '%s' failed\"), src);\n \t\t}\n"},{"id":"470125","messageId":"87sfggfybp.fsf@igel.home","threadId":"59068","inReplyTo":"20230111214337.ybrmiyeius5xzalf@tb-raspi4","subject":"Re: Misleading error message on a failed `git mv`","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2023-01-11T23:25:46Z","receivedAt":"2023-01-11T23:25:56Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jan 11 2023, Torsten Bögershausen wrote:\n\n> diff --git a/builtin/mv.c b/builtin/mv.c\n> index 19790ce38f..58e24889c0 100644\n> --- a/builtin/mv.c\n> +++ b/builtin/mv.c\n> @@ -452,8 +452,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n>  \t\tif (!(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) &&\n>  \t\t    !(dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&\n>  \t\t    rename(src, dst) < 0) {\n> +\t\t\tstruct stat st;\n>  \t\t\tif (ignore_errors)\n>  \t\t\t\tcontinue;\n> +\t\t\tif (!lstat(src, &st)) {\n> +\t\t\t\tdie_errno(_(\"moving '%s' into destination '%s' failed\"), src, dst);\n> +\t\t\t}\n\nThat will lose errno, though.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"}]}