Skip to content

Commit ffabfdb

Browse files
committed
Show file level changes
1 parent 887b65d commit ffabfdb

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Diff for: src/info.rs

+22-14
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,8 @@ impl Info {
517517
let output = Command::new("git")
518518
.arg("-C")
519519
.arg(dir)
520-
.arg("diff")
521-
.arg("--shortstat")
522-
.arg("HEAD")
520+
.arg("status")
521+
.arg("--porcelain")
523522
.output()
524523
.expect("Failed to execute git.");
525524

@@ -528,17 +527,26 @@ impl Info {
528527
if output == "" {
529528
Ok("".into())
530529
} else {
531-
let result = String::from(output)
532-
.replace(",", &"")
533-
.replace("\n", &"")
534-
.replace(" files changed", &"+-")
535-
.replace(" file changed", &"+-")
536-
.replace(" insertions(+)", &"+")
537-
.replace(" insertion(+)", &"+")
538-
.replace(" deletions(-)", &"-")
539-
.replace(" deletion(-)", &"-");
540-
541-
Ok(result.trim().into())
530+
let lines = output.lines();
531+
532+
let mut deleted = 0;
533+
let mut added = 0;
534+
let mut modified = 0;
535+
536+
for line in lines {
537+
let prefix = &line[..2];
538+
539+
match prefix.trim() {
540+
"D" => deleted += 1,
541+
"A" | "??" => added += 1,
542+
"M" | "MM" => modified += 1,
543+
_ => {}
544+
}
545+
}
546+
547+
let result = format!("{}+- {}+ {}-", modified, added, deleted);
548+
549+
Ok(result.into())
542550
}
543551
}
544552

0 commit comments

Comments
 (0)