]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-add.c
Test and fix normalize_path_copy()
[thirdparty/git.git] / builtin-add.c
index 9b2ee8c136f6e653d0b076894d9438e2ac4315ef..fc3f96eaefff91e4e85adb92162716939f0ecd72 100644 (file)
@@ -140,7 +140,8 @@ static void refresh(int verbose, const char **pathspec)
        for (specs = 0; pathspec[specs];  specs++)
                /* nothing */;
        seen = xcalloc(specs, 1);
-       refresh_index(&the_index, verbose ? 0 : REFRESH_QUIET, pathspec, seen);
+       refresh_index(&the_index, verbose ? REFRESH_SAY_CHANGED : REFRESH_QUIET,
+                     pathspec, seen);
        for (i = 0; i < specs; i++) {
                if (!seen[i])
                        die("pathspec '%s' did not match any files", pathspec[i]);
@@ -190,7 +191,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;
+static int ignore_add_errors, addremove;
 
 static struct option builtin_add_options[] = {
        OPT__DRY_RUN(&show_only),
@@ -200,6 +201,7 @@ static struct option builtin_add_options[] = {
        OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"),
        OPT_BOOLEAN('f', "force", &ignored_too, "allow adding otherwise ignored files"),
        OPT_BOOLEAN('u', "update", &take_worktree_changes, "update tracked files"),
+       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_END(),
@@ -254,6 +256,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
        git_config(add_config, NULL);
 
+       if (addremove && take_worktree_changes)
+               die("-A and -u are mutually incompatible");
+       if (addremove && !argc) {
+               static const char *here[2] = { ".", NULL };
+               argc = 1;
+               argv = here;
+       }
+
        add_new_files = !take_worktree_changes && !refresh_only;
        require_pathspec = !take_worktree_changes;
 
@@ -286,7 +296,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                goto finish;
        }
 
-       if (take_worktree_changes)
+       if (take_worktree_changes || addremove)
                exit_status |= add_files_to_cache(prefix, pathspec, flags);
 
        if (add_new_files)