{"thread":{"id":"43755","subject":"Patch: git-add --exclude=pattern","startedAt":"2006-12-02T21:29:50Z","lastAt":"2006-12-02T21:29:50Z","messageCount":1,"participants":["Adam J. Richter"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"297992","messageId":"20061203052950.A26793@freya","threadId":"43755","inReplyTo":null,"subject":"Patch: git-add --exclude=pattern","fromName":"Adam J. Richter","fromEmail":"adam@yggdrasil.com","sentAt":"2006-12-02T21:29:50Z","receivedAt":"2006-12-02T21:29:50Z","isPatch":false,"sender":{"key":"adam@yggdrasil.com","avatar":null},"body":"\tgit-ls-files has an argument \"--exclude=<pattern>\".  I have\ncopied the relevant code snippets to do the same for git-add-files.\n\n\tI want this facility so that I can disable processing of\n.gitignore files for some shell scripts that I've cobbled together\nto update git repositories from tar files of new versions of software\npackages.  Adding \"!*\" to .git/info/exclude does not achieve this,\nbecause the .gitignore files have priority, and I can see arguments\nwhy this should be so, so that .git/info/exclude can just encode\ndefaults and individual directories can have more specific rules.\nIn comparison, passing \"--exclude='!*'\" apparently does have priority\nover the .gitignore files.\n\n\tBy the way, the particular situation where I had this problem\nwas in linux-2.6.19, which shoots itself in the foot a bit by including\n.gitignore files that exclude source files like arch/*/kernel/vmlinux.ld.S,\ninclude/asm-*/{alternative-asm,frame}.i and the .cvsignore files themselves.\nHowever, fixing this linux kernel problem is not the point of this email.\nI want a facility that can reliably add files from source trees even if\nthey have minor bugs like this in their .gitignore rules.\n\n\tMany thanks to ShadeHawk on the git IRC channel for pointing\nout to me that the git-find-ls manual page actually describes the problem\nand a fix for the case of vmlinux.ld.S in the linux kernel tree, and for\nsuggesting --exclude=pattern instead of --exclude-per-directory=filename.\n\nAdam Richter\n\n\ndiff --git a/src/builtin-add.c b/src/builtin-add.c\nindex febb75e..a501b50 100644\n--- a/src/builtin-add.c\n+++ b/src/builtin-add.c\n@@ -11,7 +11,7 @@\n #include \"cache-tree.h\"\n \n static const char builtin_add_usage[] =\n-\"git-add [-n] [-v] <filepattern>...\";\n+\"git-add [--exclude=<pattern>] [-n] [-v] <filepattern>...\";\n \n static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)\n {\n@@ -55,7 +55,6 @@ static void fill_directory(struct dir_st\n \tint baselen;\n \n \t/* Set up the default git porcelain excludes */\n-\tmemset(dir, 0, sizeof(*dir));\n \tdir->exclude_per_dir = \".gitignore\";\n \tpath = git_path(\"info/exclude\");\n \tif (!access(path, R_OK))\n@@ -90,6 +89,7 @@ int cmd_add(int argc, const char **argv,\n \tconst char **pathspec;\n \tstruct dir_struct dir;\n \n+\tmemset(&dir, 0, sizeof(dir));\n \tgit_config(git_default_config);\n \n \tnewfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);\n@@ -106,6 +106,10 @@ int cmd_add(int argc, const char **argv,\n \t\t\ti++;\n \t\t\tbreak;\n \t\t}\n+\t\tif (!strncmp(arg, \"--exclude=\", 10)) {\n+\t\t\tadd_exclude(arg+10, \"\", 0, &dir.exclude_list[EXC_CMDL]);\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(arg, \"-n\")) {\n \t\t\tshow_only = 1;\n \t\t\tcontinue;\n"}]}