@@ -96,7 +96,14 @@ pub fn updated_master_branch(
9696 Err ( "Cannot find any suitable upstream master branch" . to_owned ( ) )
9797}
9898
99- fn get_git_merge_base ( config : & GitConfig < ' _ > , git_dir : Option < & Path > ) -> Result < String , String > {
99+ /// Finds the nearest merge commit by comparing the local `HEAD` with the upstream branch's state.
100+ /// To work correctly, the upstream remote must be properly configured using `git remote add <name> <url>`.
101+ /// In most cases `get_closest_merge_commit` is the function you are looking for as it doesn't require remote
102+ /// to be configured.
103+ fn git_upstream_merge_base (
104+ config : & GitConfig < ' _ > ,
105+ git_dir : Option < & Path > ,
106+ ) -> Result < String , String > {
100107 let updated_master = updated_master_branch ( config, git_dir) ?;
101108 let mut git = Command :: new ( "git" ) ;
102109 if let Some ( git_dir) = git_dir {
@@ -105,9 +112,10 @@ fn get_git_merge_base(config: &GitConfig<'_>, git_dir: Option<&Path>) -> Result<
105112 Ok ( output_result ( git. arg ( "merge-base" ) . arg ( & updated_master) . arg ( "HEAD" ) ) ?. trim ( ) . to_owned ( ) )
106113}
107114
108- /// Resolves the closest merge commit by the given `author` and `target_paths` .
115+ /// Searches for the nearest merge commit in the repository that also exists upstream .
109116///
110- /// If it fails to find the commit from upstream using `git merge-base`, fallbacks to HEAD.
117+ /// If it fails to find the upstream remote, it then looks for the most recent commit made
118+ /// by the merge bot by matching the author's email address with the merge bot's email.
111119pub fn get_closest_merge_commit (
112120 git_dir : Option < & Path > ,
113121 config : & GitConfig < ' _ > ,
@@ -119,7 +127,7 @@ pub fn get_closest_merge_commit(
119127 git. current_dir ( git_dir) ;
120128 }
121129
122- let merge_base = get_git_merge_base ( config, git_dir) . unwrap_or_else ( |_| "HEAD" . into ( ) ) ;
130+ let merge_base = git_upstream_merge_base ( config, git_dir) . unwrap_or_else ( |_| "HEAD" . into ( ) ) ;
123131
124132 git. args ( [
125133 "rev-list" ,
0 commit comments