@@ -162,10 +162,12 @@ pub mod stacks {
162
162
use but_settings:: AppSettings ;
163
163
use but_workspace:: { StacksFilter , stack_branches, ui} ;
164
164
use gitbutler_command_context:: CommandContext ;
165
+ use gitbutler_reference:: { Refname , RemoteRefname } ;
165
166
use gitbutler_stack:: StackId ;
166
167
use gix:: bstr:: ByteSlice ;
167
168
use gix:: refs:: Category ;
168
169
use std:: path:: Path ;
170
+ use std:: str:: FromStr ;
169
171
170
172
pub fn list (
171
173
current_dir : & Path ,
@@ -259,9 +261,40 @@ pub mod stacks {
259
261
/// Create a new stack containing only a branch with the given name.
260
262
fn create_stack_with_branch (
261
263
ctx : & CommandContext ,
264
+ project : gitbutler_project:: Project ,
262
265
name : & str ,
266
+ remote : bool ,
263
267
description : Option < & str > ,
264
- ) -> anyhow:: Result < ui:: StackEntryNoOpt > {
268
+ ) -> anyhow:: Result < ui:: StackEntry > {
269
+ let repo = ctx. gix_repo ( ) ?;
270
+ let remotes = repo. remote_names ( ) ;
271
+ if remote {
272
+ let remote_name = remotes
273
+ . first ( )
274
+ . map ( |r| r. to_str ( ) . unwrap ( ) )
275
+ . context ( "No remote found in repository" ) ?;
276
+
277
+ let ref_name = Refname :: from_str ( & format ! ( "refs/remotes/{remote_name}/{name}" ) ) ?;
278
+ let remote_ref_name = RemoteRefname :: new ( remote_name, name) ;
279
+
280
+ let ( stack_id, _) = gitbutler_branch_actions:: create_virtual_branch_from_branch (
281
+ ctx,
282
+ & ref_name,
283
+ Some ( remote_ref_name) ,
284
+ None ,
285
+ ) ?;
286
+
287
+ let stack_entries =
288
+ but_workspace:: stacks ( ctx, & project. gb_dir ( ) , & repo, Default :: default ( ) ) ?;
289
+ let stack_entry = stack_entries
290
+ . into_iter ( )
291
+ . find ( |entry| entry. id == Some ( stack_id) )
292
+ . ok_or_else ( || {
293
+ anyhow:: anyhow!( "Failed to find newly created stack with ID: {stack_id}" )
294
+ } ) ?;
295
+ return Ok ( stack_entry) ;
296
+ } ;
297
+
265
298
let creation_request = gitbutler_branch:: BranchCreateRequest {
266
299
name : Some ( name. to_string ( ) ) ,
267
300
..Default :: default ( )
@@ -281,7 +314,7 @@ pub mod stacks {
281
314
) ?;
282
315
}
283
316
284
- Ok ( stack_entry)
317
+ Ok ( stack_entry. into ( ) )
285
318
}
286
319
287
320
/// Add a branch to an existing stack.
@@ -330,6 +363,7 @@ pub mod stacks {
330
363
name : & str ,
331
364
description : Option < & str > ,
332
365
current_dir : & Path ,
366
+ remote : bool ,
333
367
use_json : bool ,
334
368
ws3 : bool ,
335
369
) -> anyhow:: Result < ( ) > {
@@ -353,7 +387,7 @@ pub mod stacks {
353
387
354
388
let stack_entry = match id {
355
389
Some ( id) => add_branch_to_stack ( & ctx, id, name, description, project. clone ( ) , & repo) ?,
356
- None => create_stack_with_branch ( & ctx, name, description) ?. into ( ) ,
390
+ None => create_stack_with_branch ( & ctx, project . clone ( ) , name, remote , description) ?,
357
391
} ;
358
392
359
393
if use_json {
0 commit comments