Skip to content

Commit c185520

Browse files
committed
Integrate existing branch names for rename_branch calls
Modified claude.rs to collect existing branch names from all stack heads. Passed existing branch names to rename_branch via RenameBranchParams. Refactored rename_branch invocation to use the new parameters struct. This integration supports generating unique and non-conflicting branch names in rename operations.
1 parent e010489 commit c185520

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

crates/but/src/command/claude.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::io::{self, Read};
22
use std::str::FromStr;
33

44
use anyhow::anyhow;
5+
use but_action::rename_branch::RenameBranchParams;
56
use but_action::{ActionHandler, OpenAiProvider, Source, reword::CommitEvent};
67
use but_db::ClaudeCodeSession;
78
use but_hunk_assignment::HunkAssignmentRequest;
@@ -111,6 +112,10 @@ pub(crate) async fn handle_stop() -> anyhow::Result<ClaudeHookOutput> {
111112
)?;
112113

113114
let stacks = crate::log::stacks(defer.ctx)?;
115+
let existing_branch_names = stacks
116+
.iter()
117+
.flat_map(|s| s.heads.iter().map(|h| h.name.clone().to_string()))
118+
.collect::<Vec<_>>();
114119

115120
// Trigger commit message generation for newly created commits
116121
// TODO: Maybe this can be done in the main app process i.e. the GitButler GUI, if avaialbe
@@ -140,17 +145,16 @@ pub(crate) async fn handle_stop() -> anyhow::Result<ClaudeHookOutput> {
140145

141146
match elegibility {
142147
RenameEligibility::Eligible(commit) => {
143-
but_action::rename_branch::rename_branch(
144-
defer.ctx,
145-
&openai_client,
146-
commit.id,
147-
commit.message,
148-
branch.stack_id,
149-
branch.branch_name.clone(),
150-
id,
151-
)
152-
.await
153-
.ok();
148+
let params = RenameBranchParams {
149+
commit_id: commit.id,
150+
commit_message: commit.message,
151+
stack_id: branch.stack_id,
152+
current_branch_name: branch.branch_name.clone(),
153+
existing_branch_names: existing_branch_names.clone(),
154+
};
155+
but_action::rename_branch::rename_branch(defer.ctx, &openai_client, params, id)
156+
.await
157+
.ok();
154158
}
155159
RenameEligibility::NotEligible => {
156160
// Do nothing, branch is not eligible for renaming

0 commit comments

Comments
 (0)