Merge branch 'mw/symlinks'
[gitweb.git] / builtin / add.c
index ae0bdc78bbf47094a2f0656ef8f3f561e60dc072..672adc01ffc07fa97c305f9110cfa3995658b922 100644 (file)
@@ -208,8 +208,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
        i = dir->nr;
        while (--i >= 0) {
                struct dir_entry *entry = *src++;
-               if (match_pathspec_depth(pathspec, entry->name, entry->len,
-                                        prefix, seen))
+               if (dir_path_match(entry, pathspec, prefix, seen))
                        *dst++ = entry;
                else if (flag & WARN_IMPLICIT_DOT)
                        /*
@@ -270,13 +269,7 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
 {
        struct pathspec pathspec;
 
-       /*
-        * git-add--interactive itself does not parse pathspec. It
-        * simply passes the pathspec to other builtin commands. Let's
-        * hope all of them support all magic, or we'll need to limit
-        * the magic here.
-        */
-       parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
+       parse_pathspec(&pathspec, 0,
                       PATHSPEC_PREFER_FULL |
                       PATHSPEC_SYMLINK_LEADING_PATH |
                       PATHSPEC_PREFIX_ORIGIN,
@@ -302,7 +295,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
 
        if (read_cache() < 0)
-               die (_("Could not read the index"));
+               die(_("Could not read the index"));
 
        init_revisions(&rev, prefix);
        rev.diffopt.context = 7;
@@ -313,11 +306,11 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
        DIFF_OPT_SET(&rev.diffopt, IGNORE_DIRTY_SUBMODULES);
        out = open(file, O_CREAT | O_WRONLY, 0666);
        if (out < 0)
-               die (_("Could not open '%s' for writing."), file);
+               die(_("Could not open '%s' for writing."), file);
        rev.diffopt.file = xfdopen(out, "w");
        rev.diffopt.close_file = 1;
        if (run_diff_files(&rev, 0))
-               die (_("Could not write patch"));
+               die(_("Could not write patch"));
 
        launch_editor(file, NULL, NULL);
 
@@ -330,7 +323,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
        child.git_cmd = 1;
        child.argv = apply_argv;
        if (run_command(&child))
-               die (_("Could not apply '%s'"), file);
+               die(_("Could not apply '%s'"), file);
 
        unlink(file);
        free(file);
@@ -546,11 +539,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                               PATHSPEC_FROMTOP |
                               PATHSPEC_LITERAL |
                               PATHSPEC_GLOB |
-                              PATHSPEC_ICASE);
+                              PATHSPEC_ICASE |
+                              PATHSPEC_EXCLUDE);
 
                for (i = 0; i < pathspec.nr; i++) {
                        const char *path = pathspec.items[i].match;
-                       if (!seen[i] &&
+                       if (pathspec.items[i].magic & PATHSPEC_EXCLUDE)
+                               continue;
+                       if (!seen[i] && path[0] &&
                            ((pathspec.items[i].magic &
                              (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
                             !file_exists(path))) {
@@ -588,7 +584,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
        unplug_bulk_checkin();
 
- finish:
+finish:
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
                    commit_locked_index(&lock_file))