author | Junio C Hamano <gitster@pobox.com> | |
Mon, 29 Mar 2010 04:21:42 +0000 (21:21 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 29 Mar 2010 04:21:42 +0000 (21:21 -0700) |
* cp/add-u-pathspec:
test for add with non-existent pathspec
git add -u: die on unmatched pathspec
test for add with non-existent pathspec
git add -u: die on unmatched pathspec
builtin-add.c | patch | blob | history | |
t/t2200-add-update.sh | patch | blob | history | |
t/t3700-add.sh | patch | blob | history |
diff --git a/builtin-add.c b/builtin-add.c
index 2705f8d057a93f7b4a9351713b89fd9f4e041815..87d2980313e71afc08df3eacde4a99a8468ff874 100644 (file)
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -117,7 +117,19 @@ static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)
}
}
-static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
+static char *find_used_pathspec(const char **pathspec)
+{
+ char *seen;
+ int i;
+
+ for (i = 0; pathspec[i]; i++)
+ ; /* just counting */
+ seen = xcalloc(i, 1);
+ fill_pathspec_matches(pathspec, seen, i);
+ return seen;
+}
+
+static char *prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
{
char *seen;
int i, specs;
@@ -137,13 +149,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
}
dir->nr = dst - dir->entries;
fill_pathspec_matches(pathspec, seen, specs);
-
- for (i = 0; i < specs; i++) {
- if (!seen[i] && pathspec[i][0] && !file_exists(pathspec[i]))
- die("pathspec '%s' did not match any files",
- pathspec[i]);
- }
- free(seen);
+ return seen;
}
static void treat_gitlinks(const char **pathspec)
int flags;
int add_new_files;
int require_pathspec;
+ char *seen = NULL;
git_config(add_config, NULL);
/* This picks up the paths that are not tracked */
baselen = fill_directory(&dir, pathspec);
if (pathspec)
- prune_directory(&dir, pathspec, baselen);
+ seen = prune_directory(&dir, pathspec, baselen);
}
if (refresh_only) {
goto finish;
}
+ if (pathspec) {
+ int i;
+ if (!seen)
+ seen = find_used_pathspec(pathspec);
+ for (i = 0; pathspec[i]; i++) {
+ if (!seen[i] && pathspec[i][0]
+ && !file_exists(pathspec[i]))
+ die("pathspec '%s' did not match any files",
+ pathspec[i]);
+ }
+ free(seen);
+ }
+
exit_status |= add_files_to_cache(prefix, pathspec, flags);
if (add_new_files)
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index 912075063b9946d38a9ff72621cb80bcf2c05399..2ad2819a345af53ff6ab0b7c28fa313f1a0a5956 100755 (executable)
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
'
+test_expect_success '"add -u non-existent" should fail' '
+ test_must_fail git add -u non-existent &&
+ ! (git ls-files | grep "non-existent")
+'
+
test_done
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 85eb0fbf96a65ad958422da02ca4975fe687da95..525c9a8fdfb4953612e6946994c8e555f676bfd2 100755 (executable)
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
git add track-this
'
+test_expect_success '"add non-existent" should fail' '
+ test_must_fail git add non-existent &&
+ ! (git ls-files | grep "non-existent")
+'
+
test_done