git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Misleading error message on a failed `git mv`

From
Torsten Bögershausen <tboegi@web.de>
Date
Jan 11, 2023, 21:43 UTC
Message-ID
<20230111214337.ybrmiyeius5xzalf@tb-raspi4>
In-Reply-To
<Y78I5E/BCr1QQ6aL@coredump.intra.peff.net>
On Wed, Jan 11, 2023 at 02:07:16PM -0500, Jeff King wrote:
Show 32 quoted lines
> On Wed, Jan 11, 2023 at 05:19:29AM +0100, Arthur Milchior wrote:
>
> > Error message is
> >
> > fatal: renaming 'file' failed: No such file or directory
> >
> >
> > What's different between what you expected and what actually happened?
> >
> > The error message seems to indicate that file does not exists. It
> > actually exists. The destination directory does not exists and is the
> > one that should be mentionned.
>
> I agree the message is not specific as to which case happened, but this
> is all we get from the kernel's error reporting. We called rename(), the
> syscall returned ENOENT, and we fed that to strerror() to get "No such
> file or directory". From the manpage for rename(2):
>
>   ENOENT The link named by oldpath does not exist; or, a directory
> 	 component in newpath does not exist; or, oldpath or newpath is
> 	 an empty string.
>
> If we wanted to be more specific, we'd have to go to extra work to
> diagnose each case. Most tools don't bother. For example:
>
>   $ touch foo
>   $ mv foo bar/foo
>   mv: cannot move 'foo' to 'bar/foo': No such file or directory
>
> It's quirky, for sure, but it's how most Unix tools behave here.
>
> -Peff

We may be able to inform the user that the destination is the problem, and not the source. Is this worth to do the following ? Any thoughts ?

diff --git a/builtin/mv.c b/builtin/mv.c
index 19790ce38f..58e24889c0 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -452,8 +452,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 		if (!(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) &&
 		    !(dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&
 		    rename(src, dst) < 0) {
+			struct stat st;
 			if (ignore_errors)
 				continue;
+			if (!lstat(src, &st)) {
+				die_errno(_("moving '%s' into destination '%s' failed"), src, dst);
+			}
 			die_errno(_("renaming '%s' failed"), src);
 		}
Previous: Jeff KingNext: Andreas Schwab
Message 3 of 4 in “Misleading error message on a failed `git mv`”
  1. Arthur MilchiorJan 11, 2023
  2. Jeff KingJan 11, 2023
  3. Torsten BögershausenJan 11, 2023
  4. Andreas SchwabJan 11, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.