diff --git a/src/targets.rs b/src/targets.rs index 81f2d47..b11f734 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -2,8 +2,9 @@ use std::collections::HashSet; use std::io::{self, BufRead, Read}; use std::path::{Path, PathBuf}; use globset::{Glob, GlobSetBuilder}; -use ignore::WalkBuilder; +use ignore::{WalkBuilder, overrides::OverrideBuilder}; use git2::{Repository, StatusOptions, Delta}; +use crate::utils::generic::OVERRIDE_INCLUDE_PATTERNS; #[derive(Debug)] pub struct TargetResolutionResult { @@ -423,8 +424,17 @@ fn resolve_glob(pattern: &str, repo_root: &Path) -> Result, String> let mut files = Vec::new(); + let mut override_builder = OverrideBuilder::new(repo_root); + for pattern in OVERRIDE_INCLUDE_PATTERNS { + override_builder.add(&format!("!{}", pattern)) + .map_err(|e| format!("Failed to add override pattern: {}", e))?; + } + let overrides = override_builder.build() + .map_err(|e| format!("Failed to build overrides: {}", e))?; + let walker = WalkBuilder::new(repo_root) .standard_filters(true) + .overrides(overrides) .build(); for result in walker { diff --git a/src/utils/generic.rs b/src/utils/generic.rs index 627ddda..fb8d3ae 100644 --- a/src/utils/generic.rs +++ b/src/utils/generic.rs @@ -1,7 +1,7 @@ use std::io; use std::path::{Path, PathBuf}; use zip::{write::FileOptions, ZipWriter}; -use ignore::WalkBuilder; +use ignore::{WalkBuilder, overrides::OverrideBuilder}; use globset::{GlobSetBuilder, Glob}; use std::fs::{self, File}; use std::env; @@ -31,6 +31,11 @@ const DEFAULT_EXCLUDE_GLOBS: &[&str] = &[ "**/.idea/**", ]; +// Patterns to include even if ignored by .gitignore +pub const OVERRIDE_INCLUDE_PATTERNS: &[&str] = &[ + "**/project.assets.json", +]; + /// Create a zip file from a target specification or full repository scan. /// /// - If `target` is `None`, performs a full repository scan (equivalent to scanning all files). @@ -70,8 +75,18 @@ pub fn create_zip_from_target>( .collect() } else { let directory = Path::new("."); + + let mut override_builder = OverrideBuilder::new(directory); + for pattern in OVERRIDE_INCLUDE_PATTERNS { + override_builder.add(&format!("!{}", pattern)) + .map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to add override pattern: {}", e)))?; + } + let overrides = override_builder.build() + .map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to build overrides: {}", e)))?; + let walker = WalkBuilder::new(directory) .standard_filters(true) + .overrides(overrides) .build(); let mut files = Vec::new();