271
N_("The following paths are ignored by one of your .gitignore files:\n");
272
273
static int verbose, show_only, ignored_too, refresh_only;
274
-static int ignore_add_errors, addremove, intent_to_add, ignore_missing;
274
+static int ignore_add_errors, intent_to_add, ignore_missing;
275
+
276
+#define ADDREMOVE_DEFAULT 0 /* Change to 1 in Git 2.0 */
277
+static int addremove = ADDREMOVE_DEFAULT;
278
+static int addremove_explicit = -1; /* unspecified */
279
280
static struct option builtin_add_options[] = {
281
OPT__DRY_RUN(&show_only, N_("dry run")),
287
OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files")),
288
OPT_BOOL('u', "update", &take_worktree_changes, N_("update tracked files")),
289
OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")),
286
- OPT_BOOL('A', "all", &addremove, N_("add changes from all tracked and untracked files")),
290
+ OPT_BOOL('A', "all", &addremove_explicit, N_("add changes from all tracked and untracked files")),
291
OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
292
OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
293
OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
354
option_name, short_name);
355
}
356
357
+static int directory_given(int argc, const char **argv)
358
+{
359
+ struct stat st;
360
+
361
+ while (argc--) {
362
+ if (!lstat(*argv, &st) && S_ISDIR(st.st_mode))
363
+ return 1;
364
+ argv++;
365
+ }
366
+ return 0;
367
+}
368
+
369
int cmd_add(int argc, const char **argv, const char *prefix)
370
{
371
int exit_status = 0;
393
argc--;
394
argv++;
395
396
+ if (0 <= addremove_explicit)
397
+ addremove = addremove_explicit;
398
+ else if (take_worktree_changes && ADDREMOVE_DEFAULT)
399
+ addremove = 0; /* "-u" was given but not "-A" */
400
+
401
if (addremove && take_worktree_changes)
402
die(_("-A and -u are mutually incompatible"));
403
+
404
+ /*
405
+ * Warn when "git add pathspec..." was given without "-u" or "-A"
406
+ * and pathspec... contains a directory name.
407
+ */
408
+ if (!take_worktree_changes && addremove_explicit < 0 &&
409
+ directory_given(argc, argv))
410
+ warning(_("In Git 2.0, 'git add <pathspec>...' will also update the\n"
411
+ "index for paths removed from the working tree that match\n"
412
+ "the given pathspec. If you want to 'add' only changed\n"
413
+ "or newly created paths, say 'git add --no-all <pathspec>...'"
414
+ " instead."));
415
+
416
+ if (!take_worktree_changes && addremove_explicit < 0 && argc)
417
+ /*
418
+ * Turn "git add pathspec..." to "git add -A pathspec..."
419
+ * in Git 2.0 but not yet
420
+ */
421
+ ; /* addremove = 1; */
422
+
423
if (!show_only && ignore_missing)
424
die(_("Option --ignore-missing can only be used together with --dry-run"));
425
if (addremove) {