@@ -321,6 +321,35 @@ static int add_files(struct dir_struct *dir, int flags)
321
321
return exit_status ;
322
322
}
323
323
324
+ static void warn_pathless_add (const char * option_name , const char * short_name ) {
325
+ /*
326
+ * To be consistent with "git add -p" and most Git
327
+ * commands, we should default to being tree-wide, but
328
+ * this is not the original behavior and can't be
329
+ * changed until users trained themselves not to type
330
+ * "git add -u" or "git add -A". For now, we warn and
331
+ * keep the old behavior. Later, this warning can be
332
+ * turned into a die(...), and eventually we may
333
+ * reallow the command with a new behavior.
334
+ */
335
+ warning (_ ("The behavior of 'git add %s (or %s)' with no path argument from a\n"
336
+ "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
337
+ "To add content for the whole tree, run:\n"
338
+ "\n"
339
+ " git add %s :/\n"
340
+ " (or git add %s :/)\n"
341
+ "\n"
342
+ "To restrict the command to the current directory, run:\n"
343
+ "\n"
344
+ " git add %s .\n"
345
+ " (or git add %s .)\n"
346
+ "\n"
347
+ "With the current Git version, the command is restricted to the current directory." ),
348
+ option_name , short_name ,
349
+ option_name , short_name ,
350
+ option_name , short_name );
351
+ }
352
+
324
353
int cmd_add (int argc , const char * * argv , const char * prefix )
325
354
{
326
355
int exit_status = 0 ;
@@ -331,6 +360,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
331
360
int add_new_files ;
332
361
int require_pathspec ;
333
362
char * seen = NULL ;
363
+ const char * option_with_implicit_dot = NULL ;
364
+ const char * short_option_with_implicit_dot = NULL ;
334
365
335
366
git_config (add_config , NULL );
336
367
@@ -350,8 +381,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
350
381
die (_ ("-A and -u are mutually incompatible" ));
351
382
if (!show_only && ignore_missing )
352
383
die (_ ("Option --ignore-missing can only be used together with --dry-run" ));
353
- if ((addremove || take_worktree_changes ) && !argc ) {
384
+ if (addremove ) {
385
+ option_with_implicit_dot = "--all" ;
386
+ short_option_with_implicit_dot = "-A" ;
387
+ }
388
+ if (take_worktree_changes ) {
389
+ option_with_implicit_dot = "--update" ;
390
+ short_option_with_implicit_dot = "-u" ;
391
+ }
392
+ if (option_with_implicit_dot && !argc ) {
354
393
static const char * here [2 ] = { "." , NULL };
394
+ if (prefix )
395
+ warn_pathless_add (option_with_implicit_dot ,
396
+ short_option_with_implicit_dot );
355
397
argc = 1 ;
356
398
argv = here ;
357
399
}
0 commit comments