Merge branch 'kd/mailinfo-quoted-string' into maint
[gitweb.git] / builtin / mv.c
index a2014266b6b33d7940627777af9ae860c7850c2d..2f43877bc9a17c5bef2906a383cc8cdd6f4f5b82 100644 (file)
@@ -26,7 +26,7 @@ static const char **internal_copy_pathspec(const char *prefix,
        int i;
        const char **result;
        ALLOC_ARRAY(result, count + 1);
-       memcpy(result, pathspec, count * sizeof(const char *));
+       COPY_ARRAY(result, pathspec, count);
        result[count] = NULL;
        for (i = 0; i < count; i++) {
                int length = strlen(result[i]);
@@ -104,7 +104,7 @@ static int index_range_of_same_dir(const char *src, int length,
 
 int cmd_mv(int argc, const char **argv, const char *prefix)
 {
-       int i, gitmodules_modified = 0;
+       int i, flags, gitmodules_modified = 0;
        int verbose = 0, show_only = 0, force = 0, ignore_errors = 0;
        struct option builtin_mv_options[] = {
                OPT__VERBOSE(&verbose, N_("be verbose")),
@@ -134,10 +134,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
        modes = xcalloc(argc, sizeof(enum update_mode));
        /*
         * Keep trailing slash, needed to let
-        * "git mv file no-such-dir/" error out.
+        * "git mv file no-such-dir/" error out, except in the case
+        * "git mv directory no-such-dir/".
         */
-       dest_path = internal_copy_pathspec(prefix, argv + argc, 1,
-                                          KEEP_TRAILING_SLASH);
+       flags = KEEP_TRAILING_SLASH;
+       if (argc == 1 && is_directory(argv[0]) && !is_directory(argv[1]))
+               flags = 0;
+       dest_path = internal_copy_pathspec(prefix, argv + argc, 1, flags);
        submodule_gitfile = xcalloc(argc, sizeof(char *));
 
        if (dest_path[0][0] == '\0')