Skip to content

Commit

Permalink
Merge pull request #643 from baz-scm/json-output-respect-unchanged-files
Browse files Browse the repository at this point in the history
Allow JSON output to respect skip-unchanged
  • Loading branch information
Wilfred authored Feb 19, 2024
2 parents 6f192d9 + 679d1ce commit 9032c2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/display/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
summary::{DiffResult, FileContent, FileFormat},
};

#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, PartialEq)]
#[serde(rename_all = "lowercase")]
enum Status {
Unchanged,
Expand Down Expand Up @@ -273,8 +273,12 @@ impl Highlight {
}
}

pub(crate) fn print_directory(diffs: Vec<DiffResult>) {
let files = diffs.iter().map(File::from).collect::<Vec<File>>();
pub(crate) fn print_directory(diffs: Vec<DiffResult>, print_unchanged: bool) {
let files = diffs
.iter()
.map(File::from)
.filter(|f| print_unchanged || f.status != Status::Unchanged)
.collect::<Vec<File>>();
println!(
"{}",
serde_json::to_string(&files).expect("failed to serialize files")
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn main() {
encountered_changes = results
.iter()
.any(|diff_result| diff_result.has_reportable_change());
display::json::print_directory(results);
display::json::print_directory(results, display_options.print_unchanged);
} else if display_options.sort_paths {
let mut result: Vec<DiffResult> = diff_iter.collect();
result.sort_unstable_by(|a, b| a.display_path.cmp(&b.display_path));
Expand Down

0 comments on commit 9032c2f

Please sign in to comment.