git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Misleading error message on a failed `git mv`
@ 2023-01-11  4:19 Arthur Milchior
  2023-01-11 19:07 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Arthur Milchior @ 2023-01-11  4:19 UTC (permalink / raw)
  To: git

Thanks for git, and happy new year.
Here is what I believe to be a bug in an error message

Thank you for filling out a Git bug report!

Please answer the following questions to help us understand your issue.


What did you do before the bug happened? (Steps to reproduce your issue)

git init

touch file

git add file

git mv file folder/file


What did you expect to happen? (Expected behavior)

Either creating folder, or stating that folder does not exists


What happened instead? (Actual behavior)

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.


Anything else you want to add:


Please review the rest of the bug report below.

You can delete any lines you don't wish to share.



[System Info]

git version:

git version 2.39.0.314.g84b9a713c41-goog

cpu: x86_64

no commit associated with this build

sizeof-long: 8

sizeof-size_t: 8

shell-path: /bin/sh

feature: fsmonitor--daemon

uname: Darwin 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51
PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 x86_64

compiler info: clang: 13.1.6 (clang-1316.0.21.2.5)

libc info: no libc information available

$SHELL (typically, interactive shell): /bin/bash



[Enabled Hooks]

Regards,
Arthur

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misleading error message on a failed `git mv`
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2023-01-11 19:07 UTC (permalink / raw)
  To: Arthur Milchior; +Cc: git

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misleading error message on a failed `git mv`
  2023-01-11 19:07 ` Jeff King
@ 2023-01-11 21:43   ` Torsten Bögershausen
  2023-01-11 23:25     ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Torsten Bögershausen @ 2023-01-11 21:43 UTC (permalink / raw)
  To: Jeff King; +Cc: Arthur Milchior, git

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Misleading error message on a failed `git mv`
  2023-01-11 21:43   ` Torsten Bögershausen
@ 2023-01-11 23:25     ` Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2023-01-11 23:25 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: Jeff King, Arthur Milchior, git

On Jan 11 2023, Torsten Bögershausen wrote:

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

That will lose errno, though.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-11 23:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2023-01-11 23:25     ` Andreas Schwab

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).