summaryrefslogtreecommitdiff
path: root/builtin-add.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-12-25 03:13:45 -0800
committerJunio C Hamano <junkio@cox.net>2006-12-25 03:29:08 -0800
commite23ca9e1f95a756bfe598568be9d03059db1dad2 (patch)
treeab1e60a204db751935224bfae53db6709a9e46ad /builtin-add.c
parent4888c534099012d71d24051deb5b14319747bd1a (diff)
downloadgit-e23ca9e1f95a756bfe598568be9d03059db1dad2.tar.gz
git-add: add ignored files when asked explicitly.
One thing many people found confusing about git-add was that a file whose name matches an ignored pattern could not be added to the index. With this, such a file can be added by explicitly spelling its name to git-add. Fileglobs and recursive behaviour do not add ignored files to the index. That is, if a pattern '*.o' is in .gitignore, and two files foo.o, bar/baz.o are in the working tree: $ git add foo.o $ git add '*.o' $ git add bar Only the first form adds foo.o to the index. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-add.c')
-rw-r--r--builtin-add.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/builtin-add.c b/builtin-add.c
index 17641b433d..822075ac22 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -26,7 +26,14 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
i = dir->nr;
while (--i >= 0) {
struct dir_entry *entry = *src++;
- if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) {
+ int how = match_pathspec(pathspec, entry->name, entry->len,
+ prefix, seen);
+ /*
+ * ignored entries can be added with exact match,
+ * but not with glob nor recursive.
+ */
+ if (!how ||
+ (entry->ignored_entry && how != MATCHED_EXACTLY)) {
free(entry);
continue;
}
@@ -55,6 +62,8 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
/* Set up the default git porcelain excludes */
memset(dir, 0, sizeof(*dir));
+ if (pathspec)
+ dir->show_both = 1;
dir->exclude_per_dir = ".gitignore";
path = git_path("info/exclude");
if (!access(path, R_OK))