Code

gitview.txt: improve asciidoc markup
[git.git] / builtin-mv.c
index 1fdb0c77f6ff348fd0ea466b0a78e46ed9362af8..fd1e52098174be212c51b957280f38dc6e9c0e48 100644 (file)
@@ -26,7 +26,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
                if (length > 0 && result[i][length - 1] == '/') {
                        char *without_slash = xmalloc(length);
                        memcpy(without_slash, result[i], length - 1);
-                       without_slash[length] = '\0';
+                       without_slash[length - 1] = '\0';
                        result[i] = without_slash;
                }
                if (base_name) {
@@ -114,7 +114,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
        modes = xcalloc(count, sizeof(enum update_mode));
        dest_path = copy_pathspec(prefix, argv + argc - 1, 1, 0);
 
-       if (!lstat(dest_path[0], &st) &&
+       if (dest_path[0][0] == '\0')
+               /* special case: "." was normalized to "" */
+               destination = copy_pathspec(dest_path[0], argv + i, count, 1);
+       else if (!lstat(dest_path[0], &st) &&
                        S_ISDIR(st.st_mode)) {
                dest_path[0] = add_slash(dest_path[0]);
                destination = copy_pathspec(dest_path[0], argv + i, count, 1);
@@ -259,10 +262,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
        } else {
                for (i = 0; i < changed.nr; i++) {
                        const char *path = changed.items[i].path;
-                       int i = cache_name_pos(path, strlen(path));
-                       struct cache_entry *ce = active_cache[i];
+                       int j = cache_name_pos(path, strlen(path));
+                       struct cache_entry *ce = active_cache[j];
 
-                       if (i < 0)
+                       if (j < 0)
                                die ("Huh? Cache entry for %s unknown?", path);
                        refresh_cache_entry(ce, 0);
                }