@@ -24,7 +24,7 @@ use crate::utils::mobile_app::{
2424use crate :: utils:: mobile_app:: { is_aab_file, is_apk_file, is_zip_file, normalize_directory} ;
2525use crate :: utils:: progress:: ProgressBar ;
2626use crate :: utils:: vcs:: {
27- self , get_provider_from_remote, get_repo_from_remote, git_repo_remote_url,
27+ self , get_provider_from_remote, get_repo_from_remote, git_repo_head_ref , git_repo_remote_url,
2828} ;
2929
3030pub fn make_command ( command : Command ) -> Command {
@@ -107,10 +107,11 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
107107
108108 let cached_remote = config. get_cached_vcs_remote ( ) ;
109109 // Try to open the git repository and find the remote, but handle errors gracefully.
110- let ( vcs_provider, head_repo_name) = {
110+ let ( vcs_provider, head_repo_name, head_ref ) = {
111111 // Try to open the repo and get the remote URL, but don't fail if not in a repo.
112112 let repo = git2:: Repository :: open_from_env ( ) . ok ( ) ;
113- let remote_url = repo. and_then ( |repo| git_repo_remote_url ( & repo, & cached_remote) . ok ( ) ) ;
113+ let repo_ref = repo. as_ref ( ) ;
114+ let remote_url = repo_ref. and_then ( |repo| git_repo_remote_url ( repo, & cached_remote) . ok ( ) ) ;
114115
115116 let vcs_provider: Option < Cow < ' _ , str > > = matches
116117 . get_one ( "vcs_provider" )
@@ -134,13 +135,22 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
134135 . map ( Cow :: Owned )
135136 } ) ;
136137
137- ( vcs_provider, head_repo_name)
138+ let head_ref: Option < Cow < ' _ , str > > = matches
139+ . get_one ( "head_ref" )
140+ . map ( String :: as_str)
141+ . map ( Cow :: Borrowed )
142+ . or_else ( || {
143+ // Try to get the current ref from the VCS if not provided
144+ repo_ref
145+ . and_then ( |r| git_repo_head_ref ( r) . ok ( ) )
146+ . map ( Cow :: Owned )
147+ } ) ;
148+
149+ ( vcs_provider, head_repo_name, head_ref)
138150 } ;
139151
140152 let base_repo_name = matches. get_one ( "base_repo_name" ) . map ( String :: as_str) ;
141-
142153 let base_sha = matches. get_one ( "base_sha" ) . map ( String :: as_str) ;
143- let head_ref = matches. get_one ( "head_ref" ) . map ( String :: as_str) ;
144154 let base_ref = matches. get_one ( "base_ref" ) . map ( String :: as_str) ;
145155 let pr_number = matches. get_one :: < u32 > ( "pr_number" ) ;
146156
@@ -207,7 +217,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
207217 vcs_provider : vcs_provider. as_deref ( ) ,
208218 head_repo_name : head_repo_name. as_deref ( ) ,
209219 base_repo_name,
210- head_ref,
220+ head_ref : head_ref . as_deref ( ) ,
211221 base_ref,
212222 pr_number,
213223 } ;
0 commit comments