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

Method execute

core/src/tools/builtin/git.rs:107–161  ·  view source on GitHub ↗
(&self, args: &serde_json::Value, ctx: &ToolContext)

Source from the content-addressed store, hash-verified

105 }
106
107 async fn execute(&self, args: &serde_json::Value, ctx: &ToolContext) -> Result<ToolOutput> {
108 let command = match args.get("command").and_then(|v| v.as_str()) {
109 Some(c) => c,
110 None => return Ok(ToolOutput::error("command parameter is required")),
111 };
112
113 let Some(git) = ctx.workspace_services.git() else {
114 return Ok(ToolOutput::error(
115 "Git is not available for this workspace backend",
116 ));
117 };
118
119 match git.is_repository().await {
120 Ok(true) => {}
121 Ok(false) => {
122 return Ok(ToolOutput::error(format!(
123 "Not a git repository: {}",
124 ctx.workspace_services.workspace_ref().display_root
125 )))
126 }
127 Err(e) => {
128 return Ok(ToolOutput::error(format!(
129 "Failed to inspect git repository: {e}"
130 )))
131 }
132 }
133
134 match command {
135 "status" => self.status(ctx, git.as_ref()).await,
136 "log" => self.log(args, git.as_ref()).await,
137 "branch" => self.branch(args, git.as_ref()).await,
138 "checkout" => self.checkout(args, git.as_ref()).await,
139 "diff" => self.diff(args, git.as_ref()).await,
140 "stash" => {
141 let Some(stash) = ctx.workspace_services.git_stash() else {
142 return Ok(ToolOutput::error(
143 "Stash operations are not supported by this workspace backend",
144 ));
145 };
146 self.stash(args, stash.as_ref()).await
147 }
148 "remote" => self.remote(git.as_ref()).await,
149 "worktree" => {
150 let Some(worktree) = ctx.workspace_services.git_worktree() else {
151 return Ok(ToolOutput::error(
152 "Worktree operations are not supported by this workspace backend",
153 ));
154 };
155 self.worktree(args, worktree.as_ref()).await
156 }
157 _ => Ok(ToolOutput::error(format!(
158 "Unknown command: {command}. Use: status, log, branch, checkout, diff, stash, remote, worktree"
159 ))),
160 }
161 }
162}
163
164impl GitTool {

Callers 2

test_git_not_installedFunction · 0.45
test_missing_commandFunction · 0.45

Calls 14

branchMethod · 0.80
git_stashMethod · 0.80
remoteMethod · 0.80
git_worktreeMethod · 0.80
worktreeMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
gitMethod · 0.45
is_repositoryMethod · 0.45
statusMethod · 0.45
logMethod · 0.45
checkoutMethod · 0.45

Tested by 2

test_git_not_installedFunction · 0.36
test_missing_commandFunction · 0.36