MCPcopy Index your code
hub / github.com/AI45Lab/Code / branch

Method branch

core/src/tools/builtin/git.rs:237–280  ·  view source on GitHub ↗

Branch operations: list or create.

(&self, args: &serde_json::Value, git: &dyn WorkspaceGit)

Source from the content-addressed store, hash-verified

235
236 /// Branch operations: list or create.
237 async fn branch(&self, args: &serde_json::Value, git: &dyn WorkspaceGit) -> Result<ToolOutput> {
238 let name = args.get("name").and_then(|v| v.as_str());
239
240 if let Some(branch_name) = name {
241 let base = args.get("base").and_then(|v| v.as_str()).unwrap_or("HEAD");
242
243 match git
244 .create_branch(WorkspaceGitCreateBranchRequest {
245 name: branch_name.to_string(),
246 base: base.to_string(),
247 })
248 .await
249 {
250 Ok(_) => Ok(ToolOutput::success(format!(
251 "Created branch: {} (based on {})",
252 branch_name, base
253 ))
254 .with_metadata(serde_json::json!({ "branch": branch_name, "base": base }))),
255 Err(e) => Ok(ToolOutput::error(format!("Failed to create branch: {e}"))),
256 }
257 } else {
258 match git.list_branches().await {
259 Ok(branches) => {
260 if branches.is_empty() {
261 return Ok(ToolOutput::success("No branches found."));
262 }
263
264 let entries: Vec<String> = branches
265 .iter()
266 .map(|branch| {
267 let prefix = if branch.is_current { "* " } else { " " };
268 format!("{}{}", prefix, branch.name)
269 })
270 .collect();
271
272 Ok(
273 ToolOutput::success(format!("Branches:\n{}", entries.join("\n")))
274 .with_metadata(serde_json::json!({ "count": branches.len() })),
275 )
276 }
277 Err(e) => Ok(ToolOutput::error(format!("Failed to list branches: {e}"))),
278 }
279 }
280 }
281
282 /// Checkout a branch or commit.
283 async fn checkout(

Callers 1

executeMethod · 0.80

Calls 6

getMethod · 0.45
as_strMethod · 0.45
create_branchMethod · 0.45
with_metadataMethod · 0.45
list_branchesMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected