@@ -89,7 +89,10 @@ pub async fn exec(
8989) -> Result < ( ) > {
9090 match cmd {
9191 Some ( Subcommands :: User { cmd } ) => user_config ( ctx, out, cmd) . await ,
92- Some ( Subcommands :: Target { branch } ) => target_config ( ctx, out, branch) . await ,
92+ Some ( Subcommands :: Target {
93+ branch,
94+ push_remote,
95+ } ) => target_config ( ctx, out, branch, push_remote) . await ,
9396 Some ( Subcommands :: Forge { cmd } ) => forge_config ( out, cmd) . await ,
9497 Some ( Subcommands :: Metrics { status } ) => metrics_config ( out, status) . await ,
9598 Some ( Subcommands :: Ai { local, global, cmd } ) => {
@@ -1764,6 +1767,7 @@ async fn target_config(
17641767 ctx : & mut Context ,
17651768 out : & mut OutputChannel ,
17661769 branch : Option < String > ,
1770+ push_remote : Option < String > ,
17671771) -> Result < ( ) > {
17681772 let t = theme:: get ( ) ;
17691773 match branch {
@@ -1866,17 +1870,26 @@ async fn target_config(
18661870 ) ?;
18671871 }
18681872
1869- // from the new_branch string, we need to parse out the remote name and branch name
1873+ if let Some ( push_remote) = push_remote. as_deref ( ) {
1874+ ctx. repo
1875+ . get ( ) ?
1876+ . find_remote ( push_remote)
1877+ . with_context ( || format ! ( "Failed to find push remote '{push_remote}'" ) ) ?;
1878+ }
1879+
1880+ let target_ref: gix:: refs:: FullName = format ! ( "refs/remotes/{new_branch}" )
1881+ . try_into ( )
1882+ . context ( "Invalid target branch name" ) ?;
1883+ drop ( ( guard, ws) ) ;
18701884 cfg_if ! {
18711885 if #[ cfg( feature = "legacy" ) ] {
1872- drop( ( guard, ws) ) ;
1873- but_api:: legacy:: virtual_branches:: set_base_branch(
1886+ but_api:: workspace:: set_target_ref_and_init_project(
18741887 ctx,
1875- new_branch . clone ( ) ,
1876- None ,
1888+ target_ref . as_ref ( ) ,
1889+ push_remote ,
18771890 ) ?;
18781891 } else {
1879- anyhow:: bail!( "Cannot yet set the base- branch without legacy functions - needs port " )
1892+ anyhow:: bail!( "Cannot yet set the target branch without legacy functions" )
18801893 }
18811894 } ;
18821895 }
0 commit comments