git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Jeff King <peff@peff.net>
Cc: Arthur Milchior <arthur.milchior@gmail.com>, git@vger.kernel.org
Subject: Re: Misleading error message on a failed `git mv`
Date: Wed, 11 Jan 2023 22:43:37 +0100	[thread overview]
Message-ID: <20230111214337.ybrmiyeius5xzalf@tb-raspi4> (raw)
In-Reply-To: <Y78I5E/BCr1QQ6aL@coredump.intra.peff.net>

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);
 		}

  reply	other threads:[~2023-01-11 21:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11  4:19 Misleading error message on a failed `git mv` Arthur Milchior
2023-01-11 19:07 ` Jeff King
2023-01-11 21:43   ` Torsten Bögershausen [this message]
2023-01-11 23:25     ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230111214337.ybrmiyeius5xzalf@tb-raspi4 \
    --to=tboegi@web.de \
    --cc=arthur.milchior@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).