]> git.ipfire.org Git - thirdparty/git.git/commit
mv: name both source and destination when rename fails
authorLucas Zamboni Orioli <lucaszam0@gmail.com>
Thu, 30 Jul 2026 11:28:03 +0000 (11:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Jul 2026 16:22:59 +0000 (09:22 -0700)
commit7d57eb4d34b832456f6c074f8a25bb643d2d63f2
tree4ec9c9f7c83d01c2f5c91718b1a45aa7b550abc0
parente9019fcafe0040228b8631c30f97ae1adb61bcdc
mv: name both source and destination when rename fails

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c