Skip to content

Commit b58cc47

Browse files
authored
Merge pull request #10507 from gitbutlerapp/kv-branch-55
feat(branch): check for existing git ref before creating branch
2 parents 9fa2ba1 + 181a771 commit b58cc47

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crates/but/src/branch/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, _json: bool) -> anyhow::Resul
2929
branch_name,
3030
anchor,
3131
} => {
32+
let ctx =
33+
CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
3234
// Get branch name or use canned name
3335
let branch_name = if let Some(name) = branch_name {
36+
let repo = ctx.gix_repo()?;
37+
if repo.try_find_reference(name)?.is_some() {
38+
println!("Branch '{name}' already exists");
39+
return Ok(());
40+
}
3441
name.clone()
3542
} else {
3643
but_api::workspace::canned_branch_name(project.id)?
3744
};
3845
let anchor = if let Some(anchor_str) = anchor {
3946
// Use the new create_reference API when anchor is provided
40-
let ctx = CommandContext::open(
41-
&project,
42-
AppSettings::load_from_default_path_creating()?,
43-
)?;
4447
let mut ctx = ctx; // Make mutable for CliId resolution
4548

4649
// Resolve the anchor string to a CliId

0 commit comments

Comments
 (0)