Code

Merge branch 'js/rerere'
[git.git] / builtin-add.c
index f548b8007de79d66f7ed3fad0d96bce75c6bbf57..f306f82b16c3c3c76416610cd4cabf0a307924ed 100644 (file)
@@ -3,8 +3,6 @@
  *
  * Copyright (C) 2006 Linus Torvalds
  */
-#include <fnmatch.h>
-
 #include "cache.h"
 #include "builtin.h"
 #include "dir.h"
@@ -70,7 +68,6 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
        base = "";
        if (baselen) {
                char *common = xmalloc(baselen + 1);
-               common = xmalloc(baselen + 1);
                memcpy(common, *pathspec, baselen);
                common[baselen] = 0;
                path = base = common;
@@ -93,12 +90,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file());
-       if (newfd < 0)
-               die("unable to create new index file");
-
-       if (read_cache() < 0)
-               die("index file corrupt");
+       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
 
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
@@ -117,7 +109,12 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                        verbose = 1;
                        continue;
                }
-               die(builtin_add_usage);
+               usage(builtin_add_usage);
+       }
+       if (argc <= i) {
+               fprintf(stderr, "Nothing specified, nothing added.\n");
+               fprintf(stderr, "Maybe you wanted to say 'git add .'?\n");
+               return 0;
        }
        pathspec = get_pathspec(prefix, argv + i);
 
@@ -134,6 +131,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                return 0;
        }
 
+       if (read_cache() < 0)
+               die("index file corrupt");
+
        for (i = 0; i < dir.nr; i++)
                add_file_to_index(dir.entries[i]->name, verbose);