X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin%2Fadd.c;h=17149cfeedcc39956dc55f8b72acc1227fed5213;hb=94fdb6f6ebcfe2842e8648dd88389e2e850723e9;hp=87d2980313e71afc08df3eacde4a99a8468ff874;hpb=72d9b222a940c93a8d915c26a4d5d077e23be871;p=git.git diff --git a/builtin/add.c b/builtin/add.c index 87d298031..21dc1f733 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -261,12 +261,14 @@ static int edit_patch(int argc, const char **argv, const char *prefix) { char *file = xstrdup(git_path("ADD_EDIT.patch")); const char *apply_argv[] = { "apply", "--recount", "--cached", - file, NULL }; + NULL, NULL }; struct child_process child; struct rev_info rev; int out; struct stat st; + apply_argv[3] = file; + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ if (read_cache() < 0) @@ -308,27 +310,29 @@ static const char ignore_error[] = "The following paths are ignored by one of your .gitignore files:\n"; static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0; -static int ignore_add_errors, addremove, intent_to_add; +static int ignore_add_errors, addremove, intent_to_add, ignore_missing = 0; static struct option builtin_add_options[] = { - OPT__DRY_RUN(&show_only), - OPT__VERBOSE(&verbose), + OPT__DRY_RUN(&show_only, "dry run"), + OPT__VERBOSE(&verbose, "be verbose"), OPT_GROUP(""), OPT_BOOLEAN('i', "interactive", &add_interactive, "interactive picking"), OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"), OPT_BOOLEAN('e', "edit", &edit_interactive, "edit current diff and apply"), - OPT_BOOLEAN('f', "force", &ignored_too, "allow adding otherwise ignored files"), + OPT__FORCE(&ignored_too, "allow adding otherwise ignored files"), OPT_BOOLEAN('u', "update", &take_worktree_changes, "update tracked files"), OPT_BOOLEAN('N', "intent-to-add", &intent_to_add, "record only the fact that the path will be added later"), OPT_BOOLEAN('A', "all", &addremove, "add all, noticing removal of tracked files"), OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"), OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, "just skip files which cannot be added because of errors"), + OPT_BOOLEAN( 0 , "ignore-missing", &ignore_missing, "check if - even missing - files are ignored in dry run"), OPT_END(), }; static int add_config(const char *var, const char *value, void *cb) { - if (!strcasecmp(var, "add.ignore-errors")) { + if (!strcasecmp(var, "add.ignoreerrors") || + !strcasecmp(var, "add.ignore-errors")) { ignore_add_errors = git_config_bool(var, value); return 0; } @@ -383,6 +387,8 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (addremove && take_worktree_changes) die("-A and -u are mutually incompatible"); + if (!show_only && ignore_missing) + die("Option --ignore-missing can only be used together with --dry-run"); if ((addremove || take_worktree_changes) && !argc) { static const char *here[2] = { ".", NULL }; argc = 1; @@ -439,9 +445,14 @@ int cmd_add(int argc, const char **argv, const char *prefix) seen = find_used_pathspec(pathspec); for (i = 0; pathspec[i]; i++) { if (!seen[i] && pathspec[i][0] - && !file_exists(pathspec[i])) - die("pathspec '%s' did not match any files", - pathspec[i]); + && !file_exists(pathspec[i])) { + if (ignore_missing) { + if (excluded(&dir, pathspec[i], DT_UNKNOWN)) + dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i])); + } else + die("pathspec '%s' did not match any files", + pathspec[i]); + } } free(seen); }