From 6588bbc98ca080696251b693f71e1202f29415e1 Mon Sep 17 00:00:00 2001 From: "Jason M. Gates" Date: Thu, 2 May 2024 09:44:20 -0600 Subject: [PATCH] clean-ignore: handle .gitignore exclusions My repository's `.gitignore` has, among other things, *.mat !path/to/particular.mat Running `clean-ignore --path-glob "*"` results in all `*.mat` files being stripped from the repository history. If I run git check-ignore --verbose --non-matching --no-index path/to/particular.mat I see .gitignore:2:!path/to/particular.mat path/to/particular.mat clean-ignore didn't take into account exclusions within the `.gitignore` file; it would just look at the printed paths and consider them all to be ignored. Tweak it to notice the exclusions, so that it will notice in this case that path/to/particular.mat is _not_ ignored. Signed-off-by: Jason M. Gates [en: touched up the commit message, avoid the decode, fix small error] Signed-off-by: Elijah Newren --- contrib/filter-repo-demos/clean-ignore | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/filter-repo-demos/clean-ignore b/contrib/filter-repo-demos/clean-ignore index 06823eed..95651d02 100755 --- a/contrib/filter-repo-demos/clean-ignore +++ b/contrib/filter-repo-demos/clean-ignore @@ -55,8 +55,12 @@ class CheckIgnores: if rest == b'::': self.okay.add(name) else: - self.ignored.add(name) - ignored.add(name) + rule = rest.split(b":")[-1] + if rule[0:1] == b"!": + self.okay.add(name) + else: + self.ignored.add(name) + ignored.add(name) return ignored