@@ -29,7 +29,13 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
29
29
branch_name,
30
30
anchor,
31
31
} => {
32
- if let Some ( anchor_str) = anchor {
32
+ // Get branch name or use canned name
33
+ let branch_name = if let Some ( name) = branch_name {
34
+ name. clone ( )
35
+ } else {
36
+ but_api:: workspace:: canned_branch_name ( project. id ) ?
37
+ } ;
38
+ let anchor = if let Some ( anchor_str) = anchor {
33
39
// Use the new create_reference API when anchor is provided
34
40
let ctx = CommandContext :: open (
35
41
& project,
@@ -50,15 +56,9 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
50
56
}
51
57
let anchor_id = & anchor_ids[ 0 ] ;
52
58
53
- // Get branch name or use canned name
54
- let branch_name = if let Some ( name) = branch_name {
55
- name. clone ( )
56
- } else {
57
- but_api:: workspace:: canned_branch_name ( project. id ) ?
58
- } ;
59
-
60
59
// Create the anchor for create_reference
61
- let anchor = match anchor_id {
60
+ // as dependent branch
61
+ match anchor_id {
62
62
crate :: id:: CliId :: Commit { oid } => {
63
63
Some ( but_api:: stack:: create_reference:: Anchor :: AtCommit {
64
64
commit_id : ( * oid) . into ( ) ,
@@ -77,27 +77,20 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
77
77
anchor_id. kind( )
78
78
) ) ;
79
79
}
80
- } ;
81
-
82
- // Use create_reference API
83
- let request = but_api:: stack:: create_reference:: Request {
84
- new_name : branch_name. clone ( ) ,
85
- anchor,
86
- } ;
87
- but_api:: stack:: create_reference ( project. id , request) ?;
88
- println ! ( "Created branch {branch_name}" ) ;
89
- Ok ( ( ) )
80
+ }
90
81
} else {
91
82
// Create an independent branch
92
- let req = gitbutler_branch:: BranchCreateRequest {
93
- name : branch_name. clone ( ) ,
94
- ownership : None ,
95
- order : None ,
96
- selected_for_changes : None ,
97
- } ;
98
- but_api:: virtual_branches:: create_virtual_branch ( project. id , req) ?;
99
- Ok ( ( ) )
100
- }
83
+ None
84
+ } ;
85
+ but_api:: stack:: create_reference (
86
+ project. id ,
87
+ but_api:: stack:: create_reference:: Request {
88
+ new_name : branch_name. clone ( ) ,
89
+ anchor,
90
+ } ,
91
+ ) ?;
92
+ println ! ( "Created branch {branch_name}" ) ;
93
+ Ok ( ( ) )
101
94
}
102
95
}
103
96
}
0 commit comments