@@ -113,6 +113,9 @@ pub enum PathFreshness {
113113 /// `upstream` is the latest upstream merge commit that made modifications to the
114114 /// set of paths.
115115 HasLocalModifications { upstream : String } ,
116+ /// No upstream commit was found.
117+ /// This should not happen in most reasonable circumstances, but one never knows.
118+ MissingUpstream ,
116119}
117120
118121/// This function figures out if a set of paths was last modified upstream or
@@ -177,21 +180,29 @@ pub fn check_path_modifications(
177180 // artifacts.
178181
179182 // Do not include HEAD, as it is never an upstream commit
180- get_closest_upstream_commit ( git_dir, config, ci_env) ?
183+ // If we do not find an upstream commit in CI, something is seriously wrong.
184+ Some (
185+ get_closest_upstream_commit ( git_dir, config, ci_env) ?
186+ . expect ( "No upstream commit was found on CI" ) ,
187+ )
181188 } else {
182- // Outside CI, we have to find the most recent upstream commit that
183- // modified the set of paths, to have an upstream reference.
184- let upstream_sha = get_latest_commit_that_modified_files (
189+ // Outside CI, we want to find the most recent upstream commit that
190+ // modified the set of paths, to have an upstream reference that does not change
191+ // unnecessarily often.
192+ // However, if such commit is not found, we can fall back to the latest upstream commit
193+ let upstream_with_modifications = get_latest_commit_that_modified_files (
185194 git_dir,
186195 target_paths,
187196 config. git_merge_commit_email ,
188197 ) ?;
189- let Some ( upstream_sha) = upstream_sha else {
190- eprintln ! ( "No upstream commit that modified paths {target_paths:?} found." ) ;
191- eprintln ! ( "Try to fetch more upstream history." ) ;
192- return Err ( "No upstream commit with modifications found" . to_string ( ) ) ;
193- } ;
194- upstream_sha
198+ match upstream_with_modifications {
199+ Some ( sha) => Some ( sha) ,
200+ None => get_closest_upstream_commit ( git_dir, config, ci_env) ?,
201+ }
202+ } ;
203+
204+ let Some ( upstream_sha) = upstream_sha else {
205+ return Ok ( PathFreshness :: MissingUpstream ) ;
195206 } ;
196207
197208 // For local environments, we want to find out if something has changed
@@ -253,7 +264,7 @@ fn get_closest_upstream_commit(
253264 git_dir : Option < & Path > ,
254265 config : & GitConfig < ' _ > ,
255266 env : CiEnv ,
256- ) -> Result < String , String > {
267+ ) -> Result < Option < String > , String > {
257268 let mut git = Command :: new ( "git" ) ;
258269
259270 if let Some ( git_dir) = git_dir {
@@ -264,7 +275,7 @@ fn get_closest_upstream_commit(
264275 CiEnv :: None => "HEAD" ,
265276 CiEnv :: GitHubActions => {
266277 // On CI, we always have a merge commit at the tip.
267- // We thus skip it, because although it can be creatd by
278+ // We thus skip it, because although it can be created by
268279 // `config.git_merge_commit_email`, it should not be upstream.
269280 "HEAD^1"
270281 }
@@ -277,7 +288,8 @@ fn get_closest_upstream_commit(
277288 & base,
278289 ] ) ;
279290
280- Ok ( output_result ( & mut git) ?. trim ( ) . to_owned ( ) )
291+ let output = output_result ( & mut git) ?. trim ( ) . to_owned ( ) ;
292+ if output. is_empty ( ) { Ok ( None ) } else { Ok ( Some ( output) ) }
281293}
282294
283295/// Returns the files that have been modified in the current branch compared to the master branch.
@@ -291,7 +303,9 @@ pub fn get_git_modified_files(
291303 git_dir : Option < & Path > ,
292304 extensions : & [ & str ] ,
293305) -> Result < Vec < String > , String > {
294- let merge_base = get_closest_upstream_commit ( git_dir, config, CiEnv :: None ) ?;
306+ let Some ( merge_base) = get_closest_upstream_commit ( git_dir, config, CiEnv :: None ) ? else {
307+ return Err ( "No upstream commit was found" . to_string ( ) ) ;
308+ } ;
295309
296310 let mut git = Command :: new ( "git" ) ;
297311 if let Some ( git_dir) = git_dir {
0 commit comments