X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-add.c;h=4fc9d6f7ccdd7b989d75ae6e24df997c4deb3505;hb=10455d2a955a29db1809be139177e4e298771eb0;hp=734547994f3a35e04fc7fdea10396c0c87bc6f0d;hpb=e96980ef8164f266308ea5fec536863a629866dc;p=git.git diff --git a/builtin-add.c b/builtin-add.c index 734547994..4fc9d6f7c 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -14,10 +14,9 @@ #include "revision.h" static const char builtin_add_usage[] = -"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--] ..."; +"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] ..."; static int take_worktree_changes; -static const char *excludes_file; static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix) { @@ -44,6 +43,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p die("pathspec '%s' did not match any files", pathspec[i]); } + free(seen); } static void fill_directory(struct dir_struct *dir, const char **pathspec, @@ -56,12 +56,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec, memset(dir, 0, sizeof(*dir)); if (!ignored_too) { dir->collect_ignored = 1; - dir->exclude_per_dir = ".gitignore"; - path = git_path("info/exclude"); - if (!access(path, R_OK)) - add_excludes_from_file(dir, path); - if (!access(excludes_file, R_OK)) - add_excludes_from_file(dir, excludes_file); + setup_standard_excludes(dir); } /* @@ -95,13 +90,15 @@ static void update_callback(struct diff_queue_struct *q, const char *path = p->one->path; switch (p->status) { default: - die("unexpacted diff status %c", p->status); + die("unexpected diff status %c", p->status); case DIFF_STATUS_UNMERGED: case DIFF_STATUS_MODIFIED: + case DIFF_STATUS_TYPE_CHANGED: add_file_to_cache(path, verbose); 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,41 +106,47 @@ 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; if (read_cache() < 0) die("index file corrupt"); - run_diff_files(&rev, 0); + run_diff_files(&rev, DIFF_RACY_IS_MODIFIED); } -static int git_add_config(const char *var, const char *value) +static void refresh(int verbose, const char **pathspec) { - if (!strcmp(var, "core.excludesfile")) { - if (!value) - die("core.excludesfile without value"); - excludes_file = xstrdup(value); - return 0; - } + char *seen; + int i, specs; - return git_default_config(var, value); + 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]); + } + free(seen); } static struct lock_file lock_file; -static const char ignore_warning[] = +static const char ignore_error[] = "The following paths are ignored by one of your .gitignore files:\n"; 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; @@ -162,7 +165,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) exit(1); } - git_config(git_add_config); + git_config(git_default_config); newfd = hold_locked_index(&lock_file, 1); @@ -191,11 +194,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 +213,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) { @@ -223,12 +235,12 @@ int cmd_add(int argc, const char **argv, const char *prefix) die("index file corrupt"); if (dir.ignored_nr) { - fprintf(stderr, ignore_warning); + fprintf(stderr, ignore_error); for (i = 0; i < dir.ignored_nr; i++) { fprintf(stderr, "%s\n", dir.ignored[i]->name); } fprintf(stderr, "Use -f if you really want to add them.\n"); - exit(1); + die("no files added"); } for (i = 0; i < dir.nr; i++)