git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Patch: git-add --exclude=pattern

From
ARAdam J. Richter <adam@yggdrasil.com>
Date
Dec 2, 2006, 21:29 UTC
Message-ID
<20061203052950.A26793@freya>
	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;
Message 1 of 1 in “Patch: git-add --exclude=pattern”
  1. Adam J. RichterDec 2, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.