git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] mv: fix error for moving directory to another

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 12, 2023, 01:14 UTC
Message-ID
<xmqqjzu1njt0.fsf@gitster.g>
In-Reply-To
<xmqqmsz16w1q.fsf@gitster.g>

If both directories D1 and D2 already exists, and further there is a filesystem entity D2/D1, "git mv D1 D2" would fail, and we get an error message that says:

    "cannot move directory over file, source=D1, destination=D2/D1"

regardless of the type of existing "D2/D1". If it is a file, the message is correct, but if it is a directory, it is not (we could make the D2/D1 directory a union of its original contents and what was in D1/, but that is not what we do).

The code that decies to issue the error message only checks for existence of "D2/D1" and does not care what kind of thing sits at the path.

Rephrase the message to say
    "destination already exists, source=D1, destination=D2/D1"
that would be suitable for any kind of thing being in the way.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * Just so that we do not forget what we discussed.  It is kind of
   interesting that no tests need adjustment for this change, which
   make me suspect how good our test coverage is.
   This patch has a trivial textual conflict with Sebastian's patch,
   but the resolution should be obvious.
 builtin/mv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index 665bd27448..80fc7a3c70 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -304,7 +304,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 		}
 		if (S_ISDIR(st.st_mode)
 		    && lstat(dst, &st) == 0) {
-			bad = _("cannot move directory over file");
+			bad = _("destination already exists");
 			goto act_on_entry;
 		}
 
-- 
2.42.0-rc1
Previous: Junio C HamanoNext: Sebastian Thiel via GitGitGadget
Message 6 of 7 in “fix `git mv existing-dir non-existing-dir`*”
  1. fix `git mv existing-dir non-existing-dir`*Sebastian Thiel via GitGitGadget, Aug 8, 2023
  2. Junio C HamanoAug 8, 2023
  3. Junio C HamanoAug 8, 2023
  4. Torsten BögershausenAug 8, 2023
  5. Junio C HamanoAug 8, 2023
  6. mv: fix error for moving directory to anotherJunio C Hamano, Aug 12, 2023
  7. fix `git mv existing-dir non-existing-dir` in some environments.Sebastian Thiel via GitGitGadget, Aug 9, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.