diff --git a/src/lib.rs b/src/lib.rs index 9740cb3..449d0f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,8 +17,8 @@ pub use git::{get_commits_in_range, open_repo, resolve_ref}; const SHA_ABBREV_LEN: usize = 8; /// Abbreviates a SHA to the first 8 characters (or less if shorter). -fn abbreviate_sha(sha: &str) -> &str { - &sha[..SHA_ABBREV_LEN.min(sha.len())] +pub fn abbreviate_sha(sha: &str) -> &str { + sha.get(..SHA_ABBREV_LEN).unwrap_or(sha) } /// Runs a check and reports results. diff --git a/src/main.rs b/src/main.rs index b7fcc60..197918a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 use clap::{Parser, Subcommand}; -use gitlance::{checks, git, output, run_check}; +use gitlance::{abbreviate_sha, checks, git, output, run_check}; use std::process::exit; #[derive(Parser)] @@ -45,6 +45,20 @@ enum Commands { All, } +/// Displays the list of commits being tested +fn display_commits(commits: &[git::Commit]) { + let count = commits.len(); + let plural = if count == 1 { "commit" } else { "commits" }; + println!("Testing {} {}:", count, plural); + + for commit in commits { + let sha_abbrev = abbreviate_sha(&commit.sha); + let first_line = commit.message.lines().next().unwrap_or(""); + println!(" {} {}", sha_abbrev, first_line); + } + println!(); +} + fn main() { let cli = Cli::parse(); @@ -102,6 +116,9 @@ fn main() { exit(0); } + // Display the commits being tested + display_commits(&commits); + // Run the appropriate check(s) let overall_passed = match command { Commands::WipFixup => run_check("WIP/Fixup", &checks::wip_fixup::check_commits(&commits)),