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

Re* git clean --exclude broken?

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 25, 2011, 18:29 UTC
Message-ID
<7vpqjtl4yi.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<7vfwkqmfsh.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> The documentation and the implementation of "git clean" is quite confused.
> ...
So here is a patch to fix the confusion.

It does not add a new "--except=C" I alluded to, but at least it should be the right first step to make the document clearly describe what the existing option does.

-- >8 --
Subject: [PATCH] Documentation: clarify "git clean -e <pattern>"
The current explanation of -e can be misread as allowing the user to say
    I know 'git clean -XYZ' (substitute -XYZ with any option and/or
    parameter) will remove paths A, B, and C, and I want them all removed
    except for paths matching this pattern by adding '-e C' to the same
    command line, i.e. 'git clean -e C -XYZ'.

But that is not what this option does. It augments the set of ignore rules from the command line, just like the same "-e <pattern>" argument does with the "ls-files" command (the user could probably pass "-e \!C" to tell the command to clean everything the command would normally remove, except for C).

It also fixes small style nit in the parameter to add_exclude() call. The current code only works because EXC_CMDL happens to be defined as 0.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-clean.txt |    6 +++---
 builtin/clean.c             |    5 ++++-
 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt
index 974e04e..a7a18e3 100644
--- a/Documentation/git-clean.txt
+++ b/Documentation/git-clean.txt
@@ -47,9 +47,9 @@ OPTIONS
 
 -e <pattern>::
 --exclude=<pattern>::
-	Specify special exceptions to not be cleaned.  Each <pattern> is
-	the same form as in $GIT_DIR/info/excludes and this option can be
-	given multiple times.
+	In addition to what are found in .gitignore (per directory) and
+	$GIT_DIR/info/exclude, also consider these patterns to be in the
+	set of the ignore rules in effect.
 
 -x::
 	Don't use the ignore rules.  This allows removing all untracked
diff --git a/builtin/clean.c b/builtin/clean.c
index 75697f7..3782718 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -76,6 +76,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 
 	if (ignored && ignored_only)
 		die(_("-x and -X cannot be used together"));
+	if (ignored && exclude_list.nr)
+		die(_("adding exclude with -e and ignoring it with -x is crazy"));
 
 	if (!show_only && !force) {
 		if (config_set)
@@ -98,7 +100,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 		setup_standard_excludes(&dir);
 
 	for (i = 0; i < exclude_list.nr; i++)
-		add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
+		add_exclude(exclude_list.items[i].string, "", 0,
+			    &dir.exclude_list[EXC_CMDL]);
 
 	pathspec = get_pathspec(prefix, argv);
 
Previous: Junio C HamanoNext: Michael Schubert
Message 5 of 11 in “git clean --exclude broken?”
  1. Todd RinaldoAug 24, 2011
  2. Junio C HamanoAug 24, 2011
  3. Todd RinaldoAug 24, 2011
  4. Junio C HamanoAug 25, 2011
  5. Re* git clean --exclude broken?Junio C Hamano, Aug 25, 2011
  6. Michael SchubertAug 25, 2011
  7. Junio C HamanoAug 25, 2011
  8. Thomas RastAug 26, 2011
  9. Pete WyckoffAug 27, 2011
  10. Junio C HamanoAug 28, 2011
  11. Pete WyckoffAug 28, 2011

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.