Skip to content

Commit

Permalink
Do not show prompt on no diff apply
Browse files Browse the repository at this point in the history
  • Loading branch information
riseshia committed Sep 23, 2024
1 parent 1622aa2 commit 68cfff1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ impl ApplyCommand {

let diff_result = diff(context, config).await?;

if diff_result.no_change {
return Ok(());
}

if !auto_approve {
print!(
r#"
Expand Down
10 changes: 7 additions & 3 deletions src/differ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,13 @@ pub async fn diff(context: &FuburaContext, config: &Config) -> Result<DiffResult
diff_result.append_text_diff(text_diff);
}

println!("\nFubura will:");
for (op, count) in diff_result.summary.iter() {
println!(" {}: {}", op, count);
if diff_result.no_change {
println!("\nNo diff found. Fubura will do nothing.");
} else {
println!("\nFubura will:");
for (op, count) in diff_result.summary.iter() {
println!(" {}: {}", op, count);
}
}

Ok(diff_result)
Expand Down
10 changes: 10 additions & 0 deletions src/types/diff_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ mod test {

similar_asserts::assert_eq!(expected, actual.summary);
}

#[tokio::test]
async fn test_no_change_flag() {
let mut actual = DiffResult::default();

similar_asserts::assert_eq!(true, actual.no_change);

actual.append_diff_op("NewBatch", &DiffOp::CreateState);
similar_asserts::assert_eq!(false, actual.no_change);
}
}

0 comments on commit 68cfff1

Please sign in to comment.