Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -423,8 +424,17 @@ fn resolve_glob(pattern: &str, repo_root: &Path) -> Result<Vec<PathBuf>, 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 {
Expand Down
17 changes: 16 additions & 1 deletion src/utils/generic.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -70,8 +75,18 @@ pub fn create_zip_from_target<P: AsRef<Path>>(
.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();
Expand Down