Code

Use .git/MERGE_MSG in cherry-pick/revert
[git.git] / builtin-mv.c
index 54dd3bfe8ac787fda32f3557faac00c65a61de96..3563216acaebba668f465895fe0563e5d7113fef 100644 (file)
@@ -3,8 +3,6 @@
  *
  * Copyright (C) 2006 Johannes Schindelin
  */
-#include <fnmatch.h>
-
 #include "cache.h"
 #include "builtin.h"
 #include "dir.h"
@@ -79,7 +77,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
+       newfd = hold_locked_index(&lock_file, 1);
        if (read_cache() < 0)
                die("index file corrupt");
 
@@ -146,21 +144,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                && lstat(dst, &st) == 0)
                        bad = "cannot move directory over file";
                else if (src_is_dir) {
+                       const char *src_w_slash = add_slash(src);
+                       int len_w_slash = length + 1;
                        int first, last;
 
                        modes[i] = WORKING_DIRECTORY;
 
-                       first = cache_name_pos(src, length);
+                       first = cache_name_pos(src_w_slash, len_w_slash);
                        if (first >= 0)
-                               die ("Huh? %s/ is in index?", src);
+                               die ("Huh? %.*s is in index?",
+                                               len_w_slash, src_w_slash);
 
                        first = -1 - first;
                        for (last = first; last < active_nr; last++) {
                                const char *path = active_cache[last]->name;
-                               if (strncmp(path, src, length)
-                                               || path[length] != '/')
+                               if (strncmp(path, src_w_slash, len_w_slash))
                                        break;
                        }
+                       free((char *)src_w_slash);
 
                        if (last - first < 1)
                                bad = "source directory is empty";
@@ -272,7 +273,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
                for (i = 0; i < added.nr; i++) {
                        const char *path = added.items[i].path;
-                       add_file_to_index(path, verbose);
+                       add_file_to_cache(path, verbose);
                }
 
                for (i = 0; i < deleted.nr; i++) {
@@ -284,7 +285,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                if (active_cache_changed) {
                        if (write_cache(newfd, active_cache, active_nr) ||
                            close(newfd) ||
-                           commit_lock_file(&lock_file))
+                           commit_locked_index(&lock_file))
                                die("Unable to write new index file");
                }
        }