Merge branch 'jc/add-u-A-default-to-top' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 5 Nov 2015 20:18:12 +0000 (12:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Nov 2015 20:18:12 +0000 (12:18 -0800)
"git --literal-pathspecs add -u/-A" without any command line
argument misbehaved ever since Git 2.0.

* jc/add-u-A-default-to-top:
add: simplify -u/-A without pathspec

1  2 
builtin/add.c
diff --combined builtin/add.c
index b2a5c57f0afde85a7584e1edc7a45b67d12d143d,06ad3653f0105b411d5effe219105305cb47b843..145f06ef97afd1e9e8d5cbe13da82cffa504e32c
@@@ -5,7 -5,6 +5,7 @@@
   */
  #include "cache.h"
  #include "builtin.h"
 +#include "lockfile.h"
  #include "dir.h"
  #include "pathspec.h"
  #include "exec_cmd.h"
@@@ -19,7 -18,7 +19,7 @@@
  #include "argv-array.h"
  
  static const char * const builtin_add_usage[] = {
 -      N_("git add [options] [--] <pathspec>..."),
 +      N_("git add [<options>] [--] <pathspec>..."),
        NULL
  };
  static int patch_interactive, add_interactive, edit_interactive;
@@@ -181,7 -180,7 +181,7 @@@ static int edit_patch(int argc, const c
        char *file = git_pathdup("ADD_EDIT.patch");
        const char *apply_argv[] = { "apply", "--recount", "--cached",
                NULL, NULL };
 -      struct child_process child;
 +      struct child_process child = CHILD_PROCESS_INIT;
        struct rev_info rev;
        int out;
        struct stat st;
        if (run_diff_files(&rev, 0))
                die(_("Could not write patch"));
  
 -      launch_editor(file, NULL, NULL);
 +      if (launch_editor(file, NULL, NULL))
 +              die(_("editing patch failed"));
  
        if (stat(file, &st))
                die_errno(_("Could not stat '%s'"), file);
        if (!st.st_size)
                die(_("Empty patch. Aborted."));
  
 -      memset(&child, 0, sizeof(child));
        child.git_cmd = 1;
        child.argv = apply_argv;
        if (run_command(&child))
@@@ -285,7 -284,7 +285,7 @@@ static int add_files(struct dir_struct 
                for (i = 0; i < dir->ignored_nr; i++)
                        fprintf(stderr, "%s\n", dir->ignored[i]->name);
                fprintf(stderr, _("Use -f if you really want to add them.\n"));
 -              die(_("no files added"));
 +              exit_status = 1;
        }
  
        for (i = 0; i < dir->nr; i++)
  int cmd_add(int argc, const char **argv, const char *prefix)
  {
        int exit_status = 0;
 -      int newfd;
        struct pathspec pathspec;
        struct dir_struct dir;
        int flags;
        if (!show_only && ignore_missing)
                die(_("Option --ignore-missing can only be used together with --dry-run"));
  
-       if ((0 < addremove_explicit || take_worktree_changes) && !argc) {
-               static const char *whole[2] = { ":/", NULL };
-               argc = 1;
-               argv = whole;
-       }
        add_new_files = !take_worktree_changes && !refresh_only;
-       require_pathspec = !take_worktree_changes;
+       require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
  
 -      newfd = hold_locked_index(&lock_file, 1);
 +      hold_locked_index(&lock_file, 1);
  
        flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
                 (show_only ? ADD_CACHE_PRETEND : 0) |
  
        if (add_new_files) {
                int baselen;
 -              struct pathspec empty_pathspec;
  
                /* Set up the default git porcelain excludes */
                memset(&dir, 0, sizeof(dir));
                        setup_standard_excludes(&dir);
                }
  
 -              memset(&empty_pathspec, 0, sizeof(empty_pathspec));
                /* This picks up the paths that are not tracked */
                baselen = fill_directory(&dir, &pathspec);
                if (pathspec.nr)
  
  finish:
        if (active_cache_changed) {
 -              if (write_cache(newfd, active_cache, active_nr) ||
 -                  commit_locked_index(&lock_file))
 +              if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
                        die(_("Unable to write new index file"));
        }