summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-03-08 00:46:06 -0500
committerGitHub <noreply@github.com>2024-03-08 05:46:06 +0000
commit40089b37c0a98fdcfc5b44c5ecb2c390cd16e66c (patch)
treefc6c36219d338066f789798689244a7a402d837e /cli/util
parent2c6e9107b6bd85acb249cbc802571a1c55b96227 (diff)
fix(publish): include explicitly specified .gitignored files and directories (#22790)
This allows explicitly overriding a .gitignore by specifying files and directories in "include". This does not apply to globs in an include as files matching those will still be gitignored. Additionally, individually gitignored files within an included directory will still be ignored.
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/fs.rs25
-rw-r--r--cli/util/gitignore.rs20
2 files changed, 42 insertions, 3 deletions
diff --git a/cli/util/fs.rs b/cli/util/fs.rs
index f6354097a..352e09999 100644
--- a/cli/util/fs.rs
+++ b/cli/util/fs.rs
@@ -326,7 +326,30 @@ impl<TFilter: Fn(WalkEntry) -> bool> FileCollector<TFilter> {
}
let mut maybe_git_ignores = if self.use_gitignore {
- Some(GitIgnoreTree::new(Arc::new(deno_runtime::deno_fs::RealFs)))
+ // Override explicitly specified include paths in the
+ // .gitignore file. This does not apply to globs because
+ // that is way too complicated to reason about.
+ let include_paths = file_patterns
+ .include
+ .as_ref()
+ .map(|include| {
+ include
+ .inner()
+ .iter()
+ .filter_map(|path_or_pattern| {
+ if let PathOrPattern::Path(p) = path_or_pattern {
+ Some(p.clone())
+ } else {
+ None
+ }
+ })
+ .collect::<Vec<_>>()
+ })
+ .unwrap_or_default();
+ Some(GitIgnoreTree::new(
+ Arc::new(deno_runtime::deno_fs::RealFs),
+ include_paths,
+ ))
} else {
None
};
diff --git a/cli/util/gitignore.rs b/cli/util/gitignore.rs
index da9065494..f4185aa0d 100644
--- a/cli/util/gitignore.rs
+++ b/cli/util/gitignore.rs
@@ -38,13 +38,19 @@ impl DirGitIgnores {
pub struct GitIgnoreTree {
fs: Arc<dyn deno_runtime::deno_fs::FileSystem>,
ignores: HashMap<PathBuf, Option<Rc<DirGitIgnores>>>,
+ include_paths: Vec<PathBuf>,
}
impl GitIgnoreTree {
- pub fn new(fs: Arc<dyn deno_runtime::deno_fs::FileSystem>) -> Self {
+ pub fn new(
+ fs: Arc<dyn deno_runtime::deno_fs::FileSystem>,
+ // paths that should override what's in the gitignore
+ include_paths: Vec<PathBuf>,
+ ) -> Self {
Self {
fs,
ignores: Default::default(),
+ include_paths,
}
}
@@ -94,6 +100,16 @@ impl GitIgnoreTree {
for line in text.lines() {
builder.add_line(None, line).ok()?;
}
+ // override the gitignore contents to include these paths
+ for path in &self.include_paths {
+ if let Ok(suffix) = path.strip_prefix(dir_path) {
+ let suffix = suffix.to_string_lossy().replace('\\', "/");
+ let _ignore = builder.add_line(None, &format!("!/{}", suffix));
+ if !suffix.ends_with('/') {
+ let _ignore = builder.add_line(None, &format!("!/{}/", suffix));
+ }
+ }
+ }
let gitignore = builder.build().ok()?;
Some(Rc::new(gitignore))
});
@@ -122,7 +138,7 @@ mod test {
"!file.txt\nignore.txt".into(),
),
]);
- let mut ignore_tree = GitIgnoreTree::new(Arc::new(fs));
+ let mut ignore_tree = GitIgnoreTree::new(Arc::new(fs), Vec::new());
let mut run_test = |path: &str, expected: bool| {
let path = PathBuf::from(path);
let gitignore = ignore_tree