Skip to content

Commit 9c5f1fd

Browse files
authored
Merge pull request #10492 from Byron/fix
but-cli: avoid calling functions with `virtual` in it if there are alternatives.
2 parents 592b461 + 9263759 commit 9c5f1fd

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

crates/but/src/branch/mod.rs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
2929
branch_name,
3030
anchor,
3131
} => {
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 {
3339
// Use the new create_reference API when anchor is provided
3440
let ctx = CommandContext::open(
3541
&project,
@@ -50,15 +56,9 @@ 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
61-
let anchor = match anchor_id {
60+
// as dependent branch
61+
match anchor_id {
6262
crate::id::CliId::Commit { oid } => {
6363
Some(but_api::stack::create_reference::Anchor::AtCommit {
6464
commit_id: (*oid).into(),
@@ -77,27 +77,20 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
7777
anchor_id.kind()
7878
));
7979
}
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+
}
9081
} else {
9182
// 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(())
10194
}
10295
}
10396
}

0 commit comments

Comments
 (0)