Re: [PATCH v2 1/2] mv: name both source and destination when rename fails
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 23, 2026, 17:36 UTC
- Message-ID
- <xmqqh5lpk3r3.fsf@gitster.g>
- In-Reply-To
- <0d67da588bc86c5257ce366903ae58e171159b8b.1784812390.git.gitgitgadget@gmail.com>
"Lucas Zamboni Orioli via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 44 quoted lines
> From: Lucas Zamboni Orioli <lucaszam0@gmail.com>
>
> When "git mv" fails at the rename(2) syscall, the error is reported
> with die_errno() using only the source path:
>
> fatal: renaming 'src' failed: No such file or directory
>
> rename(2) returns ENOENT both when the source does not exist and when
> a directory component of the destination does not exist, and errno
> does not distinguish the two. Reporting only the source therefore
> misleads the user in the latter case: for
>
> git mv a/file b/no-such-dir/file
>
> the message blames 'a/file', which exists, and gives no hint that
> 'b/no-such-dir/' is the missing part.
>
> Inspecting the paths again after the failure to determine which one is
> at fault would be racy, since either could appear or disappear between
> the rename(2) and the follow-up check. Instead, simply name both the
> source and the destination in the message and let the reader see which
> one is wrong:
>
> fatal: renaming 'a/file' to 'b/no-such-dir/file' failed:
> No such file or directory
>
> Signed-off-by: Lucas Zamboni Orioli <lucaszam0@gmail.com>
> ---
> builtin/mv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/mv.c b/builtin/mv.c
> index a82fc97a19..35e504484a 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -549,7 +549,7 @@ remove_entry:
> rename(src, dst) < 0) {
> if (ignore_errors)
> continue;
> - die_errno(_("renaming '%s' failed"), src);
> + die_errno(_("renaming '%s' to '%s' failed"), src, dst);
> }
> if (submodule_gitfiles[i]) {
> if (!update_path_in_gitmodules(src, dst))Makes sense.