From d84b5826bd86b5e23e406bb075b71fd9045ed9c1 Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Wed, 19 Mar 2025 20:34:46 +0000 Subject: [PATCH 1/4] Add option to use rules from .gitignore even if .pubignore present --- lib/src/package.dart | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/src/package.dart b/lib/src/package.dart index a92eaecf70..733126493e 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -239,6 +239,12 @@ See $workspacesDocUrl for more information. '/pubspec_overrides.yaml', ]; + static final _includeGitignoreIndicator = RegExp( + // We look for "#* include .gitignore" at the start of a .pubignore + // We don't necessarily care about whitespace + r'^\s*#@\s*include\s*\.gitignore\s*?$', + ); + /// Returns a list of files that are considered to be part of this package. /// /// If [beneath] is passed, this will only return files beneath that path, @@ -345,24 +351,35 @@ $symlinkResolvedDir => ${p.canonicalize(symlinkResolvedParent)} }); }, ignoreForDir: (dir) { + final rules = [if (dir == beneath) ..._basicIgnoreRules]; + var usedIgnoreFiles = ''; + final pubIgnore = resolve('$dir/.pubignore'); final gitIgnore = resolve('$dir/.gitignore'); - final ignoreFile = - fileExists(pubIgnore) - ? pubIgnore - : (fileExists(gitIgnore) ? gitIgnore : null); - - final rules = [ - if (dir == beneath) ..._basicIgnoreRules, - if (ignoreFile != null) readTextFile(ignoreFile), - ]; + + if (fileExists(pubIgnore)) { + final pubIgnoreText = readTextFile(pubIgnore); + + rules.add(pubIgnoreText); + usedIgnoreFiles = pubIgnore; + + if (pubIgnoreText.startsWith(_includeGitignoreIndicator) && + fileExists(gitIgnore)) { + rules.add(readTextFile(gitIgnore)); + usedIgnoreFiles += ' or $gitIgnore'; + } + } else if (fileExists(gitIgnore)) { + rules.add(readTextFile(gitIgnore)); + usedIgnoreFiles = gitIgnore; + } + return rules.isEmpty ? null : Ignore( rules, onInvalidPattern: (pattern, exception) { log.warning( - '$ignoreFile had invalid pattern $pattern. ' + '$usedIgnoreFiles had invalid pattern $pattern. ' '${exception.message}', ); }, From b934b75969830b538297d0e0f06395e30d7bb437 Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Wed, 19 Mar 2025 20:56:13 +0000 Subject: [PATCH 2/4] Fixed regex --- lib/src/package.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/package.dart b/lib/src/package.dart index 733126493e..44caade11f 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -241,8 +241,9 @@ See $workspacesDocUrl for more information. static final _includeGitignoreIndicator = RegExp( // We look for "#* include .gitignore" at the start of a .pubignore - // We don't necessarily care about whitespace - r'^\s*#@\s*include\s*\.gitignore\s*?$', + // We don't necessarily care about whitespace, just that it's at the start + // of the file, at the start of the line, and ends on its own line + r'^#\s*@\s*include\s*\.gitignore\s*?\r?\n', ); /// Returns a list of files that are considered to be part of this package. @@ -363,8 +364,11 @@ $symlinkResolvedDir => ${p.canonicalize(symlinkResolvedParent)} rules.add(pubIgnoreText); usedIgnoreFiles = pubIgnore; + print(pubIgnoreText.startsWith(_includeGitignoreIndicator)); + if (pubIgnoreText.startsWith(_includeGitignoreIndicator) && fileExists(gitIgnore)) { + log.warning('gitignore special'); rules.add(readTextFile(gitIgnore)); usedIgnoreFiles += ' or $gitIgnore'; } @@ -373,6 +377,8 @@ $symlinkResolvedDir => ${p.canonicalize(symlinkResolvedParent)} usedIgnoreFiles = gitIgnore; } + log.warning(usedIgnoreFiles); + return rules.isEmpty ? null : Ignore( From 100b6f70f6e15e301a44bf91c059277d467bbde4 Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Wed, 19 Mar 2025 20:56:27 +0000 Subject: [PATCH 3/4] Minor comment fix --- lib/src/package.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/package.dart b/lib/src/package.dart index 44caade11f..a95e0a2320 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -240,7 +240,7 @@ See $workspacesDocUrl for more information. ]; static final _includeGitignoreIndicator = RegExp( - // We look for "#* include .gitignore" at the start of a .pubignore + // We look for "#@ include .gitignore" at the start of a .pubignore // We don't necessarily care about whitespace, just that it's at the start // of the file, at the start of the line, and ends on its own line r'^#\s*@\s*include\s*\.gitignore\s*?\r?\n', From 82c580ec426915ad15d37cf128474ebc6c82a25a Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Wed, 19 Mar 2025 20:58:55 +0000 Subject: [PATCH 4/4] Removed debugging --- lib/src/package.dart | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/src/package.dart b/lib/src/package.dart index a95e0a2320..0a97d1ae13 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -364,11 +364,8 @@ $symlinkResolvedDir => ${p.canonicalize(symlinkResolvedParent)} rules.add(pubIgnoreText); usedIgnoreFiles = pubIgnore; - print(pubIgnoreText.startsWith(_includeGitignoreIndicator)); - if (pubIgnoreText.startsWith(_includeGitignoreIndicator) && fileExists(gitIgnore)) { - log.warning('gitignore special'); rules.add(readTextFile(gitIgnore)); usedIgnoreFiles += ' or $gitIgnore'; } @@ -377,8 +374,6 @@ $symlinkResolvedDir => ${p.canonicalize(symlinkResolvedParent)} usedIgnoreFiles = gitIgnore; } - log.warning(usedIgnoreFiles); - return rules.isEmpty ? null : Ignore(