mv: let 'git mv file no-such-dir/' error out on Windows, too
authorJohannes Sixt <j6t@kdbg.org>
Wed, 8 Jan 2014 16:33:44 +0000 (17:33 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jan 2014 19:28:12 +0000 (11:28 -0800)
The previous commit c57f628 (mv: let 'git mv file no-such-dir/' error out)
relies on that rename("file", "no-such-dir/") fails if the directory does not
exist (note the trailing slash). This does not work as expected on Windows:
This rename() call does not fail, but renames "file" to "no-such-dir" (not to
"no-such-dir/file"). Insert an explicit check for this case to force an error.

This changes the error message from

$ git mv file no-such-dir/
fatal: renaming 'file' failed: Not a directory

to

$ git mv file no-such-dir/
fatal: destination directory does not exist, source=file, destination=no-such-dir/

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c
index 08fbc033e45bba4880c8de797ef5ac0dc0b6259d..21c46d1636e6e87dd9eaaca60ac08ebbbc4efec3 100644 (file)
@@ -214,6 +214,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                        }
                } else if (string_list_has_string(&src_for_dst, dst))
                        bad = _("multiple sources for the same target");
+               else if (is_dir_sep(dst[strlen(dst) - 1]))
+                       bad = _("destination directory does not exist");
                else
                        string_list_insert(&src_for_dst, dst);