MCPcopy Create free account
hub / github.com/AI45Lab/Code / checkout

Method checkout

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

Checkout a branch or commit.

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

Source from the content-addressed store, hash-verified

281
282 /// Checkout a branch or commit.
283 async fn checkout(
284 &self,
285 args: &serde_json::Value,
286 git: &dyn WorkspaceGit,
287 ) -> Result<ToolOutput> {
288 let refspec = match args.get("ref").and_then(|v| v.as_str()) {
289 Some(r) => r,
290 None => return Ok(ToolOutput::error("ref parameter is required for checkout")),
291 };
292
293 let force = args.get("force").and_then(|v| v.as_bool()).unwrap_or(false);
294
295 match git
296 .checkout(WorkspaceGitCheckoutRequest {
297 refspec: refspec.to_string(),
298 force,
299 })
300 .await
301 {
302 Ok(output) => Ok(ToolOutput::success(format!(
303 "Checked out: {}{}",
304 refspec,
305 if output.stdout.trim().is_empty() {
306 String::new()
307 } else {
308 format!("\n{}", output.stdout)
309 }
310 ))),
311 Err(e) => Ok(ToolOutput::error(format!("Failed to checkout: {e}"))),
312 }
313 }
314
315 /// Show diff.
316 async fn diff(&self, args: &serde_json::Value, git: &dyn WorkspaceGit) -> Result<ToolOutput> {

Callers 1

executeMethod · 0.45

Calls 2

getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected