Skip to content

Commit 62ea1de

Browse files
author
Stephan Dilly
committed
fix progress 0/0 panic
1 parent 47ff937 commit 62ea1de

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

asyncgit/src/progress.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl ProgressPercent {
1515
pub fn new(current: usize, total: usize) -> Self {
1616
let total = f64::conv(cmp::max(current, total));
1717
let progress = f64::conv(current) / total * 100.0;
18-
let progress = u8::conv_nearest(progress);
18+
let progress = u8::try_conv_nearest(progress).unwrap_or(100);
1919
Self { progress }
2020
}
2121
///
@@ -39,6 +39,12 @@ mod tests {
3939
assert_eq!(prog.progress, 100);
4040
}
4141

42+
#[test]
43+
fn test_progress_zero_all() {
44+
let prog = ProgressPercent::new(0, 0);
45+
assert_eq!(prog.progress, 100);
46+
}
47+
4248
#[test]
4349
fn test_progress_rounding() {
4450
let prog = ProgressPercent::new(2, 10);

0 commit comments

Comments
 (0)