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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 11, 2023 at 02:07:16PM -0500, Jeff King wrote:
> 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);
 		}




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux