@matheusbsbs / matheus-bagliano / commits / e23ca9e1f9
Fork 0

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>

Junio C Hamano committed Dec 25, 2006 at 03:13 UTC e23ca9e1f95a756bfe598568be9d03059db1dad2
2 files changed +18 -4
Documentation/git-add.txt
+8 -3
@@ -25,8 +25,9 @@ the commit.
25 The 'git status' command can be used to obtain a summary of what is included
26 for the next commit.
27
28 -This command only adds non-ignored files, to add ignored files use
29 -"git update-index --add".
28 +This command can be used to add ignored files, but they have to be
29 +explicitly and exactly specified from the command line. File globbing
30 +and recursive behaviour do not add ignored files.
31
32 Please see gitlink:git-commit[1] for alternative ways to add content to a
33 commit.
@@ -35,7 +36,11 @@ commit.
36 OPTIONS
37 -------
38 <file>...::
38 - Files to add content from.
39 + Files to add content from. Fileglobs (e.g. `*.c`) can
40 + be given to add all matching files. Also a
41 + leading directory name (e.g. `dir` to add `dir/file1`
42 + and `dir/file2`) can be given to add all files in the
43 + directory, recursively.
44
45 -n::
46 Don't actually add the file(s), just show if they exist.
builtin-add.c
+10 -1
@@ -26,7 +26,14 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
26 i = dir->nr;
27 while (--i >= 0) {
28 struct dir_entry *entry = *src++;
29 - if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) {
29 + int how = match_pathspec(pathspec, entry->name, entry->len,
30 + prefix, seen);
31 + /*
32 + * ignored entries can be added with exact match,
33 + * but not with glob nor recursive.
34 + */
35 + if (!how ||
36 + (entry->ignored_entry && how != MATCHED_EXACTLY)) {
37 free(entry);
38 continue;
39 }
@@ -55,6 +62,8 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
62
63 /* Set up the default git porcelain excludes */
64 memset(dir, 0, sizeof(*dir));
65 + if (pathspec)
66 + dir->show_both = 1;
67 dir->exclude_per_dir = ".gitignore";
68 path = git_path("info/exclude");
69 if (!access(path, R_OK))