Merge branch 'jc/not-mingw-cygwin'
[gitweb.git] / builtin / mv.c
index 45e57f307b799490a949d60b37f8cff1a1e5d07f..6ffe540c202f69a41fcf40d443f73073d3ba08bd 100644 (file)
@@ -63,7 +63,7 @@ static struct lock_file lock_file;
 
 int cmd_mv(int argc, const char **argv, const char *prefix)
 {
-       int i, newfd, gitmodules_modified = 0;
+       int i, 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")),
@@ -85,7 +85,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
        if (--argc < 1)
                usage_with_options(builtin_mv_usage, builtin_mv_options);
 
-       newfd = hold_locked_index(&lock_file, 1);
+       hold_locked_index(&lock_file, 1);
        if (read_cache() < 0)
                die(_("index file corrupt"));
 
@@ -162,7 +162,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                        if (strncmp(path, src_w_slash, len_w_slash))
                                                break;
                                }
-                               free((char *)src_w_slash);
+                               if (src_w_slash != src)
+                                       free((char *)src_w_slash);
 
                                if (last - first < 1)
                                        bad = _("source directory is empty");
@@ -202,7 +203,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                        }
                } else if (cache_name_pos(src, length) < 0)
                        bad = _("not under version control");
-               else if (lstat(dst, &st) == 0) {
+               else if (lstat(dst, &st) == 0 &&
+                        (!ignore_case || strcasecmp(src, dst))) {
                        bad = _("destination exists");
                        if (force) {
                                /*
@@ -274,8 +276,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                stage_updated_gitmodules();
 
        if (active_cache_changed) {
-               if (write_cache(newfd, active_cache, active_nr) ||
-                   commit_locked_index(&lock_file))
+               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }