Re: [PATCH v2 2/2] mv: check for missing destination directory before renaming
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 23, 2026, 22:40 UTC
- Message-ID
- <xmqqldb1cosx.fsf@gitster.g>
- In-Reply-To
- <CAH01Q-_2APONq2fXmjF=Wo08rTzScMEjyXL-G=_GH6TbjJmTBw@mail.gmail.com>
Lucas Zamboni Orioli <lucaszam0@gmail.com> writes:
Show 11 quoted lines
>> lstat() can succeed and 'dir_st' may indicate something other than a >> directory (for example, a symbolic link or a regular file). >> Alternatively, it can fail with ENOTDIR when, for example, 'dst_dir' >> is 'a/b/c' and 'a/b' is a file rather than a directory. >> >> Both cases will cause 'git mv' into a path assumed to be a directory >> to fail. Shouldn't we handle these conditions as well? > > Yes, agreed, both should be handled. For v3 I switched from lstat() > to stat() so that the check follows symlinks the same way rename() > does, and I handle the non-directory cases:
Generally, a symbolic link in a Git-managed working tree should not be followed. Following a symbolic link would mean that 'git mv x y' could move 'x' outside the working tree if 'y' is a tracked symbolic link pointing to a directory outside the working tree. "git apply" for example avoids being fooled by a symbolic link for the same reason, for example.
I doubt that using stat() instead of lstat() is the right approach. Doing so essentially amounts to ignoring the presence of symbolic links.