Skip to content

Commit 1778b9d

Browse files
committed
detect number of commits #24
1 parent 6599801 commit 1778b9d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct Info {
2626
language: Language,
2727
authors: Vec<String>,
2828
repo: String,
29+
commits: String,
2930
number_of_lines: usize,
3031
license: String,
3132
}
@@ -75,6 +76,12 @@ impl fmt::Display for Info {
7576
}
7677

7778
writeln!(buffer, "{}{}", "Repo: ".color(color).bold(), self.repo)?;
79+
writeln!(
80+
buffer,
81+
"{}{}",
82+
"Commits: ".color(color).bold(),
83+
self.commits
84+
)?;
7885
writeln!(
7986
buffer,
8087
"{}{}",
@@ -226,13 +233,15 @@ fn main() -> Result<()> {
226233
let authors = get_authors(3);
227234
let config = get_configuration()?;
228235
let version = get_version()?;
236+
let commits = get_commits()?;
229237

230238
let info = Info {
231239
project_name: config.repository_name,
232240
version,
233241
language,
234242
authors,
235243
repo: config.repository_url,
244+
commits,
236245
number_of_lines: get_total_loc(&tokei_langs),
237246
license: project_license()?,
238247
};
@@ -295,6 +304,22 @@ fn get_version() -> Result<String> {
295304
}
296305
}
297306

307+
fn get_commits() -> Result<String> {
308+
let output = Command::new("git")
309+
.arg("rev-list")
310+
.arg("--count")
311+
.arg("HEAD")
312+
.output()
313+
.expect("Failed to execute git.");
314+
315+
let output = String::from_utf8_lossy(&output.stdout);
316+
317+
if output == "" {
318+
Ok("0".into())
319+
} else {
320+
Ok(output.to_string().replace('\n', ""))
321+
}
322+
}
298323

299324
fn is_git_installed() -> bool {
300325
Command::new("git")

0 commit comments

Comments
 (0)