@@ -96,7 +96,14 @@ pub fn updated_master_branch(
96
96
Err ( "Cannot find any suitable upstream master branch" . to_owned ( ) )
97
97
}
98
98
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 > {
100
107
let updated_master = updated_master_branch ( config, git_dir) ?;
101
108
let mut git = Command :: new ( "git" ) ;
102
109
if let Some ( git_dir) = git_dir {
@@ -105,9 +112,10 @@ fn get_git_merge_base(config: &GitConfig<'_>, git_dir: Option<&Path>) -> Result<
105
112
Ok ( output_result ( git. arg ( "merge-base" ) . arg ( & updated_master) . arg ( "HEAD" ) ) ?. trim ( ) . to_owned ( ) )
106
113
}
107
114
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 .
109
116
///
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.
111
119
pub fn get_closest_merge_commit (
112
120
git_dir : Option < & Path > ,
113
121
config : & GitConfig < ' _ > ,
@@ -119,7 +127,7 @@ pub fn get_closest_merge_commit(
119
127
git. current_dir ( git_dir) ;
120
128
}
121
129
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 ( ) ) ;
123
131
124
132
git. args ( [
125
133
"rev-list" ,
0 commit comments