@@ -321,6 +321,35 @@ static int add_files(struct dir_struct *dir, int flags)
321321 return exit_status ;
322322}
323323
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+
324353int cmd_add (int argc , const char * * argv , const char * prefix )
325354{
326355 int exit_status = 0 ;
@@ -331,6 +360,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
331360 int add_new_files ;
332361 int require_pathspec ;
333362 char * seen = NULL ;
363+ const char * option_with_implicit_dot = NULL ;
364+ const char * short_option_with_implicit_dot = NULL ;
334365
335366 git_config (add_config , NULL );
336367
@@ -350,8 +381,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
350381 die (_ ("-A and -u are mutually incompatible" ));
351382 if (!show_only && ignore_missing )
352383 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 ) {
354393 static const char * here [2 ] = { "." , NULL };
394+ if (prefix )
395+ warn_pathless_add (option_with_implicit_dot ,
396+ short_option_with_implicit_dot );
355397 argc = 1 ;
356398 argv = here ;
357399 }
0 commit comments