@@ -114,7 +114,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
114114
115115 let cached_remote = config. get_cached_vcs_remote ( ) ;
116116 // Try to open the git repository and find the remote, but handle errors gracefully.
117- let ( vcs_provider, head_repo_name, head_ref) = {
117+ let ( vcs_provider, head_repo_name, head_ref, base_ref ) = {
118118 // Try to open the repo and get the remote URL, but don't fail if not in a repo.
119119 let repo = git2:: Repository :: open_from_env ( ) . ok ( ) ;
120120 let repo_ref = repo. as_ref ( ) ;
@@ -168,33 +168,36 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
168168 . map ( Cow :: Owned )
169169 } ) ;
170170
171- ( vcs_provider, head_repo_name, head_ref)
171+ let base_ref = matches
172+ . get_one ( "base_ref" )
173+ . map ( String :: as_str)
174+ . map ( Cow :: Borrowed )
175+ . or_else ( || {
176+ // Try to get the base ref from the VCS if not provided
177+ // This attempts to find the merge-base with the remote tracking branch
178+ repo_ref
179+ . and_then ( |r| match git_repo_base_ref ( r, & cached_remote) {
180+ Ok ( Some ( base_ref_name) ) => {
181+ debug ! ( "Found base branch reference: {}" , base_ref_name) ;
182+ Some ( base_ref_name)
183+ }
184+ Ok ( None ) => {
185+ debug ! ( "No base branch reference found (no local branch points to merge-base)" ) ;
186+ None
187+ }
188+ Err ( e) => {
189+ debug ! ( "Error getting base branch reference: {}" , e) ;
190+ None
191+ }
192+ } )
193+ . map ( Cow :: Owned )
194+ } ) ;
195+
196+ ( vcs_provider, head_repo_name, head_ref, base_ref)
172197 } ;
173198
174199 let base_repo_name = matches. get_one ( "base_repo_name" ) . map ( String :: as_str) ;
175200 let base_sha = matches. get_one ( "base_sha" ) . map ( String :: as_str) ;
176- let base_ref = matches
177- . get_one ( "base_ref" )
178- . map ( String :: as_str)
179- . map ( Cow :: Borrowed )
180- . or_else ( || {
181- // Try to get the base ref from the VCS if not provided
182- // This attempts to find the merge-base with the remote tracking branch
183- if let Ok ( repo) = git2:: Repository :: open_from_env ( ) {
184- match git_repo_base_ref ( & repo, & cached_remote) {
185- Ok ( base_ref_name) => {
186- debug ! ( "Found base branch reference: {}" , base_ref_name) ;
187- Some ( Cow :: Owned ( base_ref_name) )
188- }
189- Err ( e) => {
190- debug ! ( "No base branch reference found: {}" , e) ;
191- None
192- }
193- }
194- } else {
195- None
196- }
197- } ) ;
198201 let pr_number = matches. get_one :: < u32 > ( "pr_number" ) ;
199202
200203 let build_configuration = matches. get_one ( "build_configuration" ) . map ( String :: as_str) ;
0 commit comments