@@ -2,20 +2,21 @@ use anyhow::{Context, Result};
22use std:: path:: { Path , PathBuf } ;
33use std:: process:: Command ;
44
5- /// Ensures repo is cloned/synced to cache. Returns cache path.
6- pub fn ensure_repo ( source : & str ) -> Result < PathBuf > {
5+ /// Ensures repo is cloned/synced to cache. Returns ( cache path, commit_range if updated) .
6+ pub fn ensure_repo ( source : & str ) -> Result < ( PathBuf , Option < String > ) > {
77 let cache_dir = get_cache_dir ( source) ?;
88 if let Some ( parent) = cache_dir. parent ( ) {
99 std:: fs:: create_dir_all ( parent) ?;
1010 }
1111
12- if cache_dir. exists ( ) {
13- sync_repo ( & cache_dir) ?;
12+ let update_info = if cache_dir. exists ( ) {
13+ sync_repo ( & cache_dir) ?
1414 } else {
1515 clone_repo ( source, & cache_dir) ?;
16- }
16+ Some ( "initial" . to_string ( ) )
17+ } ;
1718
18- Ok ( cache_dir)
19+ Ok ( ( cache_dir, update_info ) )
1920}
2021
2122fn clone_repo ( source : & str , dest : & Path ) -> Result < ( ) > {
@@ -34,7 +35,8 @@ fn clone_repo(source: &str, dest: &Path) -> Result<()> {
3435 Ok ( ( ) )
3536}
3637
37- fn sync_repo ( dest : & Path ) -> Result < ( ) > {
38+ /// Returns commit range (e.g. "abc123..def456") if new commits were fetched
39+ fn sync_repo ( dest : & Path ) -> Result < Option < String > > {
3840 // git clone sets up tracking branches for both local and remote repos
3941 let has_upstream = Command :: new ( "git" )
4042 . args ( [ "rev-parse" , "--abbrev-ref" , "@{upstream}" ] )
@@ -53,9 +55,23 @@ fn sync_repo(dest: &Path) -> Result<()> {
5355 let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
5456 anyhow:: bail!( "git pull failed: {}" , stderr) ;
5557 }
58+
59+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
60+ if stdout. contains ( "Already up to date" ) {
61+ return Ok ( None ) ;
62+ }
63+
64+ // Extract commit range from "Updating abc123..def456"
65+ let range = stdout
66+ . lines ( )
67+ . find ( |l| l. starts_with ( "Updating " ) )
68+ . and_then ( |l| l. strip_prefix ( "Updating " ) )
69+ . map ( |s| s. to_string ( ) ) ;
70+
71+ return Ok ( range. or_else ( || Some ( "updated" . to_string ( ) ) ) ) ;
5672 }
5773
58- Ok ( ( ) )
74+ Ok ( None )
5975}
6076
6177fn get_cache_dir ( source : & str ) -> Result < PathBuf > {
0 commit comments