Skip to content

Commit e9d30ad

Browse files
committed
but-cli: avoid calling functions with virtual in it if there are alternatives.
Based on https://github.com/gitbutlerapp/gitbutler/pull/10477/files#r2386229356
1 parent 0d0da52 commit e9d30ad

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

crates/but/src/branch/mod.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
2929
branch_name,
3030
anchor,
3131
} => {
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+
};
3238
if let Some(anchor_str) = anchor {
3339
// Use the new create_reference API when anchor is provided
3440
let ctx = CommandContext::open(
@@ -50,13 +56,6 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
5056
}
5157
let anchor_id = &anchor_ids[0];
5258

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-
6059
// Create the anchor for create_reference
6160
let anchor = match anchor_id {
6261
crate::id::CliId::Commit { oid } => {
@@ -85,19 +84,16 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
8584
anchor,
8685
};
8786
but_api::stack::create_reference(project.id, request)?;
88-
println!("Created branch {branch_name}");
89-
Ok(())
9087
} else {
9188
// 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,
89+
let request = but_api::stack::create_reference::Request {
90+
new_name: branch_name.clone(),
91+
anchor: None,
9792
};
98-
but_api::virtual_branches::create_virtual_branch(project.id, req)?;
99-
Ok(())
93+
but_api::stack::create_reference(project.id, request)?;
10094
}
95+
println!("Created branch {branch_name}");
96+
Ok(())
10197
}
10298
}
10399
}

0 commit comments

Comments
 (0)