git-ls-files has an argument "--exclude=<pattern>". I have copied the relevant code snippets to do the same for git-add-files. I want this facility so that I can disable processing of .gitignore files for some shell scripts that I've cobbled together to update git repositories from tar files of new versions of software packages. Adding "!*" to .git/info/exclude does not achieve this, because the .gitignore files have priority, and I can see arguments why this should be so, so that .git/info/exclude can just encode defaults and individual directories can have more specific rules. In comparison, passing "--exclude='!*'" apparently does have priority over the .gitignore files. By the way, the particular situation where I had this problem was in linux-2.6.19, which shoots itself in the foot a bit by including .gitignore files that exclude source files like arch/*/kernel/vmlinux.ld.S, include/asm-*/{alternative-asm,frame}.i and the .cvsignore files themselves. However, fixing this linux kernel problem is not the point of this email. I want a facility that can reliably add files from source trees even if they have minor bugs like this in their .gitignore rules. Many thanks to ShadeHawk on the git IRC channel for pointing out to me that the git-find-ls manual page actually describes the problem and a fix for the case of vmlinux.ld.S in the linux kernel tree, and for suggesting --exclude=pattern instead of --exclude-per-directory=filename. Adam Richter
diff --git a/src/builtin-add.c b/src/builtin-add.c index febb75e..a501b50 100644 --- a/src/builtin-add.c +++ b/src/builtin-add.c @@ -11,7 +11,7 @@ #include "cache-tree.h" static const char builtin_add_usage[] = -"git-add [-n] [-v] <filepattern>..."; +"git-add [--exclude=<pattern>] [-n] [-v] <filepattern>..."; static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix) { @@ -55,7 +55,6 @@ static void fill_directory(struct dir_st int baselen; /* Set up the default git porcelain excludes */ - memset(dir, 0, sizeof(*dir)); dir->exclude_per_dir = ".gitignore"; path = git_path("info/exclude"); if (!access(path, R_OK)) @@ -90,6 +89,7 @@ int cmd_add(int argc, const char **argv, const char **pathspec; struct dir_struct dir; + memset(&dir, 0, sizeof(dir)); git_config(git_default_config); newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1); @@ -106,6 +106,10 @@ int cmd_add(int argc, const char **argv, i++; break; } + if (!strncmp(arg, "--exclude=", 10)) { + add_exclude(arg+10, "", 0, &dir.exclude_list[EXC_CMDL]); + continue; + } if (!strcmp(arg, "-n")) { show_only = 1; continue;