Skip to content

Commit a893346

Browse files
j6tgitster
authored andcommitted
mv: let 'git mv file no-such-dir/' error out on Windows, too
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c57f628 commit a893346

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/mv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
214214
}
215215
} else if (string_list_has_string(&src_for_dst, dst))
216216
bad = _("multiple sources for the same target");
217+
else if (is_dir_sep(dst[strlen(dst) - 1]))
218+
bad = _("destination directory does not exist");
217219
else
218220
string_list_insert(&src_for_dst, dst);
219221

0 commit comments

Comments
 (0)