git clone: do not issue warning while cloning locally across filesystems
[gitweb.git] / builtin-add.c
index 734547994f3a35e04fc7fdea10396c0c87bc6f0d..3dd4ded937e20d326737d17cceeebb1f3f744f07 100644 (file)
@@ -60,7 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
                path = git_path("info/exclude");
                if (!access(path, R_OK))
                        add_excludes_from_file(dir, path);
-               if (!access(excludes_file, R_OK))
+               if (excludes_file != NULL && !access(excludes_file, R_OK))
                        add_excludes_from_file(dir, excludes_file);
        }
 
@@ -102,6 +102,7 @@ static void update_callback(struct diff_queue_struct *q,
                        break;
                case DIFF_STATUS_DELETED:
                        remove_file_from_cache(path);
+                       cache_tree_invalidate_path(active_cache_tree, path);
                        if (verbose)
                                printf("remove '%s'\n", path);
                        break;
@@ -109,12 +110,12 @@ static void update_callback(struct diff_queue_struct *q,
        }
 }
 
-static void update(int verbose, const char **files)
+static void update(int verbose, const char *prefix, const char **files)
 {
        struct rev_info rev;
-       init_revisions(&rev, "");
+       init_revisions(&rev, prefix);
        setup_revisions(0, NULL, &rev, NULL);
-       rev.prune_data = get_pathspec(rev.prefix, files);
+       rev.prune_data = get_pathspec(prefix, files);
        rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = update_callback;
        rev.diffopt.format_callback_data = &verbose;
@@ -123,6 +124,23 @@ static void update(int verbose, const char **files)
        run_diff_files(&rev, 0);
 }
 
+static void refresh(int verbose, const char **pathspec)
+{
+       char *seen;
+       int i, specs;
+
+       for (specs = 0; pathspec[specs];  specs++)
+               /* nothing */;
+       seen = xcalloc(specs, 1);
+       if (read_cache() < 0)
+               die("index file corrupt");
+       refresh_index(&the_index, verbose ? 0 : REFRESH_QUIET, pathspec, seen);
+       for (i = 0; i < specs; i++) {
+               if (!seen[i])
+                       die("pathspec '%s' did not match any files", pathspec[i]);
+       }
+}
+
 static int git_add_config(const char *var, const char *value)
 {
        if (!strcmp(var, "core.excludesfile")) {
@@ -143,7 +161,7 @@ static const char ignore_warning[] =
 int cmd_add(int argc, const char **argv, const char *prefix)
 {
        int i, newfd;
-       int verbose = 0, show_only = 0, ignored_too = 0;
+       int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
        const char **pathspec;
        struct dir_struct dir;
        int add_interactive = 0;
@@ -191,11 +209,15 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                        take_worktree_changes = 1;
                        continue;
                }
+               if (!strcmp(arg, "--refresh")) {
+                       refresh_only = 1;
+                       continue;
+               }
                usage(builtin_add_usage);
        }
 
        if (take_worktree_changes) {
-               update(verbose, argv + i);
+               update(verbose, prefix, argv + i);
                goto finish;
        }
 
@@ -206,6 +228,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        }
        pathspec = get_pathspec(prefix, argv + i);
 
+       if (refresh_only) {
+               refresh(verbose, pathspec);
+               goto finish;
+       }
+
        fill_directory(&dir, pathspec, ignored_too);
 
        if (show_only) {