diff options
author | Jens Lehmann <Jens.Lehmann@web.de> | 2010-07-10 00:18:38 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-07-12 15:13:54 -0700 |
commit | 108da0db1277fc2f4820d0a47c02b2c63111f7a5 (patch) | |
tree | 1684b8bab6530364e446aaa2a437d19521f04e34 /builtin/add.c | |
parent | 637ab29b86533c7ce65a615fd445d163a2c57dc9 (diff) | |
download | git-108da0db1277fc2f4820d0a47c02b2c63111f7a5.tar.gz |
git add: Add the "--ignore-missing" option for the dry run
Sometimes it is useful to know if a file or directory will be ignored
before it is added to the work tree. An example is "git submodule add",
where it would be really nice to be able to fail with an appropriate
error message before the submodule is cloned and checked out.
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/add.c')
-rw-r--r-- | builtin/add.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/builtin/add.c b/builtin/add.c index 17149cfeed..56a4e0af6b 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -310,7 +310,7 @@ 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), @@ -325,6 +325,7 @@ static struct option builtin_add_options[] = { 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(), }; @@ -385,6 +386,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; @@ -441,9 +444,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); } |