Skip to content

Commit 0d88866

Browse files
fix(snapshots): Support jpg/jpeg in diff command
The diff command only collected .png files, but the upload command supports png, jpg, and jpeg. Align the diff command to match. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 53c5bd8 commit 0d88866

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/commands/snapshots/diff.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
141141
bail!("Head directory does not exist: {}", head_dir.display());
142142
}
143143

144-
let base_files = collect_png_files(&base_dir)?;
145-
let head_files = collect_png_files(&head_dir)?;
144+
let base_files = collect_image_files(&base_dir)?;
145+
let head_files = collect_image_files(&head_dir)?;
146146
let categorized = categorize_images(&base_files, &head_files);
147147

148148
let output_diff_mask = true;
@@ -351,20 +351,26 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
351351
Ok(())
352352
}
353353

354-
fn collect_png_files(dir: &Path) -> Result<BTreeSet<PathBuf>> {
354+
const IMAGE_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg"];
355+
356+
fn collect_image_files(dir: &Path) -> Result<BTreeSet<PathBuf>> {
355357
let mut files = BTreeSet::new();
356358
for entry in WalkDir::new(dir).follow_links(true) {
357359
let entry = entry?;
358360
if !entry.file_type().is_file() {
359361
continue;
360362
}
361363
let path = entry.path();
362-
let is_png = path
364+
let is_image = path
363365
.extension()
364366
.and_then(|e| e.to_str())
365-
.map(|e| e.eq_ignore_ascii_case("png"))
367+
.map(|e| {
368+
IMAGE_EXTENSIONS
369+
.iter()
370+
.any(|ext| e.eq_ignore_ascii_case(ext))
371+
})
366372
.unwrap_or(false);
367-
if is_png {
373+
if is_image {
368374
let rel = path.strip_prefix(dir)?.to_path_buf();
369375
files.insert(rel);
370376
}

0 commit comments

Comments
 (0)