1use crate::command::Command;
2use crate::core::git::GitOperations;
3
4pub fn run(reference: String) -> crate::Result<()> {
5 let cmd = SinceCommand;
6 cmd.execute(reference)
7}
8
9pub struct SinceCommand;
11
12impl Command for SinceCommand {
13 type Input = String;
14 type Output = ();
15
16 fn execute(&self, reference: String) -> crate::Result<()> {
17 let output = run_since(&reference)?;
18 println!("{output}");
19 Ok(())
20 }
21
22 fn name(&self) -> &'static str {
23 "since"
24 }
25
26 fn description(&self) -> &'static str {
27 "Show commits since a reference (e.g., cb676ec, origin/main)"
28 }
29}
30
31fn run_since(reference: &str) -> crate::Result<String> {
32 let log_range = format!("{reference}..HEAD");
33 let log = GitOperations::run(&["log", &log_range, "--pretty=format:- %h %s"])?;
34
35 if log.trim().is_empty() {
36 Ok(format!("{} No new commits since {reference}", "✅"))
37 } else {
38 Ok(format!("🔍 Commits since {reference}:\n{log}"))
39 }
40}