开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

开发人工智能/Roo-Code

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (2166)
标签 (585)
main
renovate/testing-library-monorepo
renovate/lint-staged-16.x-lockfile
renovate/radix-ui-primitives-monorepo
renovate/npm-vite-vulnerability
renovate/npm-axios-vulnerability
changeset-release/main
fix/openai-compatible-embedding-trimming-models
renovate/dotenvx-dotenvx-1.x-lockfile
feature/mcp-marketplace-free-search-engines
fix/rename-profile-12360
feature/enhance-subtask-button-visibility
renovate/ai-sdk-deepseek-2.x-lockfile
renovate/ai-sdk-google-3.x-lockfile
feature/phase-7-consolidated
renovate/ai-sdk-amazon-bedrock-4.x-lockfile
feature/phase-7c-background-task-history
codex/roo-router-refund-error
feature/phase-7b-tool-runner-integration
feature/phase-7a-file-lock-manager
v3.54.0
v3.53.0
v3.52.1
v3.52.0
v3.51.1
v3.51.0
cli-v0.1.17
cli-v0.1.16
cli-v0.1.15
cli-v0.1.14
cli-v0.1.13
cli-v0.1.12
cli-v0.1.11
cli-v0.1.10
cli-v0.1.9
cli-v0.1.8
cli-v0.1.7
cli-v0.1.6
cli-v0.1.5
cli-v0.1.4
main
分支 (2166)
标签 (585)
main
renovate/testing-library-monorepo
renovate/lint-staged-16.x-lockfile
renovate/radix-ui-primitives-monorepo
renovate/npm-vite-vulnerability
renovate/npm-axios-vulnerability
changeset-release/main
fix/openai-compatible-embedding-trimming-models
renovate/dotenvx-dotenvx-1.x-lockfile
feature/mcp-marketplace-free-search-engines
fix/rename-profile-12360
feature/enhance-subtask-button-visibility
renovate/ai-sdk-deepseek-2.x-lockfile
renovate/ai-sdk-google-3.x-lockfile
feature/phase-7-consolidated
renovate/ai-sdk-amazon-bedrock-4.x-lockfile
feature/phase-7c-background-task-history
codex/roo-router-refund-error
feature/phase-7b-tool-runner-integration
feature/phase-7a-file-lock-manager
v3.54.0
v3.53.0
v3.52.1
v3.52.0
v3.51.1
v3.51.0
cli-v0.1.17
cli-v0.1.16
cli-v0.1.15
cli-v0.1.14
cli-v0.1.13
cli-v0.1.12
cli-v0.1.11
cli-v0.1.10
cli-v0.1.9
cli-v0.1.8
cli-v0.1.7
cli-v0.1.6
cli-v0.1.5
cli-v0.1.4
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (2166)
标签 (585)
main
renovate/testing-library-monorepo
renovate/lint-staged-16.x-lockfile
renovate/radix-ui-primitives-monorepo
renovate/npm-vite-vulnerability
renovate/npm-axios-vulnerability
changeset-release/main
fix/openai-compatible-embedding-trimming-models
renovate/dotenvx-dotenvx-1.x-lockfile
feature/mcp-marketplace-free-search-engines
fix/rename-profile-12360
feature/enhance-subtask-button-visibility
renovate/ai-sdk-deepseek-2.x-lockfile
renovate/ai-sdk-google-3.x-lockfile
feature/phase-7-consolidated
renovate/ai-sdk-amazon-bedrock-4.x-lockfile
feature/phase-7c-background-task-history
codex/roo-router-refund-error
feature/phase-7b-tool-runner-integration
feature/phase-7a-file-lock-manager
v3.54.0
v3.53.0
v3.52.1
v3.52.0
v3.51.1
v3.51.0
cli-v0.1.17
cli-v0.1.16
cli-v0.1.15
cli-v0.1.14
cli-v0.1.13
cli-v0.1.12
cli-v0.1.11
cli-v0.1.10
cli-v0.1.9
cli-v0.1.8
cli-v0.1.7
cli-v0.1.6
cli-v0.1.5
cli-v0.1.4
Roo-Code
/
src
/
utils
/
git.ts
Roo-Code
/
src
/
utils
/
git.ts
git.ts 10.82 KB
一键复制 编辑 原始数据 按行查看 历史
Matt Rubens 提交于 2026年05月12日 05:34 +08:00 . Remove all telemetry (#12324)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
import * as vscode from "vscode"
import * as path from "path"
import { promises as fs } from "fs"
import { exec } from "child_process"
import { promisify } from "util"
import type { GitRepositoryInfo, GitCommit } from "@roo-code/types"
import { truncateOutput } from "../integrations/misc/extract-text"
const execAsync = promisify(exec)
const GIT_OUTPUT_LINE_LIMIT = 500
/**
* Extracts git repository information from the workspace's .git directory
* @param workspaceRoot The root path of the workspace
* @returns Git repository information or empty object if not a git repository
*/
export async function getGitRepositoryInfo(workspaceRoot: string): Promise<GitRepositoryInfo> {
try {
const gitDir = path.join(workspaceRoot, ".git")
// Check if .git directory exists
try {
await fs.access(gitDir)
} catch {
// Not a git repository
return {}
}
const gitInfo: GitRepositoryInfo = {}
// Try to read git config file
try {
const configPath = path.join(gitDir, "config")
const configContent = await fs.readFile(configPath, "utf8")
// Very simple approach - just find any URL line
const urlMatch = configContent.match(/url\s*=\s*(.+?)(?:\r?\n|$)/m)
if (urlMatch && urlMatch[1]) {
const url = urlMatch[1].trim()
// Sanitize the URL and convert to HTTPS format
gitInfo.repositoryUrl = convertGitUrlToHttps(sanitizeGitUrl(url))
const repositoryName = extractRepositoryName(url)
if (repositoryName) {
gitInfo.repositoryName = repositoryName
}
}
// Extract default branch (if available)
const branchMatch = configContent.match(/\[branch "([^"]+)"\]/i)
if (branchMatch && branchMatch[1]) {
gitInfo.defaultBranch = branchMatch[1]
}
} catch (error) {
// Ignore config reading errors
}
// Try to read HEAD file to get current branch
if (!gitInfo.defaultBranch) {
try {
const headPath = path.join(gitDir, "HEAD")
const headContent = await fs.readFile(headPath, "utf8")
const branchMatch = headContent.match(/ref: refs\/heads\/(.+)/)
if (branchMatch && branchMatch[1]) {
gitInfo.defaultBranch = branchMatch[1].trim()
}
} catch (error) {
// Ignore HEAD reading errors
}
}
return gitInfo
} catch (error) {
// Return empty object on any error
return {}
}
}
/**
* Converts a git URL to HTTPS format
* @param url The git URL to convert
* @returns The URL in HTTPS format, or the original URL if conversion is not possible
*/
export function convertGitUrlToHttps(url: string): string {
try {
// Already HTTPS, just return it
if (url.startsWith("https://")) {
return url
}
// Handle SSH format: git@github.com:user/repo.git -> https://github.com/user/repo.git
if (url.startsWith("git@")) {
const match = url.match(/git@([^:]+):(.+)/)
if (match && match.length === 3) {
const [, host, path] = match
return `https://${host}/${path}`
}
}
// Handle SSH with protocol: ssh://git@github.com/user/repo.git -> https://github.com/user/repo.git
if (url.startsWith("ssh://")) {
const match = url.match(/ssh:\/\/(?:git@)?([^\/]+)\/(.+)/)
if (match && match.length === 3) {
const [, host, path] = match
return `https://${host}/${path}`
}
}
// Return original URL if we can't convert it
return url
} catch {
// If parsing fails, return original
return url
}
}
/**
* Sanitizes a git URL to remove sensitive information like tokens
* @param url The original git URL
* @returns Sanitized URL
*/
export function sanitizeGitUrl(url: string): string {
try {
// Remove credentials from HTTPS URLs
if (url.startsWith("https://")) {
const urlObj = new URL(url)
// Remove username and password
urlObj.username = ""
urlObj.password = ""
return urlObj.toString()
}
// For SSH URLs, return as-is (they don't contain sensitive tokens)
if (url.startsWith("git@") || url.startsWith("ssh://")) {
return url
}
// For other formats, return as-is but remove any potential tokens
return url.replace(/:[a-f0-9]{40,}@/gi, "@")
} catch {
// If URL parsing fails, return original (might be SSH format)
return url
}
}
/**
* Extracts repository name from a git URL
* @param url The git URL
* @returns Repository name or undefined
*/
export function extractRepositoryName(url: string): string {
try {
// Handle different URL formats
const patterns = [
// HTTPS: https://github.com/user/repo.git -> user/repo
/https:\/\/[^\/]+\/([^\/]+\/[^\/]+?)(?:\.git)?$/,
// SSH: git@github.com:user/repo.git -> user/repo
/git@[^:]+:([^\/]+\/[^\/]+?)(?:\.git)?$/,
// SSH with user: ssh://git@github.com/user/repo.git -> user/repo
/ssh:\/\/[^\/]+\/([^\/]+\/[^\/]+?)(?:\.git)?$/,
]
for (const pattern of patterns) {
const match = url.match(pattern)
if (match && match[1]) {
return match[1].replace(/\.git$/, "")
}
}
return ""
} catch {
return ""
}
}
/**
* Gets git repository information for the current VSCode workspace
* @returns Git repository information or empty object if not available
*/
export async function getWorkspaceGitInfo(): Promise<GitRepositoryInfo> {
const workspaceFolders = vscode.workspace.workspaceFolders
if (!workspaceFolders || workspaceFolders.length === 0) {
return {}
}
// Use the first workspace folder.
const workspaceRoot = workspaceFolders[0].uri.fsPath
return getGitRepositoryInfo(workspaceRoot)
}
async function checkGitRepo(cwd: string): Promise<boolean> {
try {
await execAsync("git rev-parse --git-dir", { cwd })
return true
} catch (error) {
return false
}
}
/**
* Checks if Git is installed on the system by attempting to run git --version
* @returns {Promise<boolean>} True if Git is installed and accessible, false otherwise
* @example
* const isGitInstalled = await checkGitInstalled();
* if (!isGitInstalled) {
* console.log("Git is not installed");
* }
*/
export async function checkGitInstalled(): Promise<boolean> {
try {
await execAsync("git --version")
return true
} catch (error) {
return false
}
}
export async function searchCommits(query: string, cwd: string): Promise<GitCommit[]> {
try {
const isInstalled = await checkGitInstalled()
if (!isInstalled) {
console.error("Git is not installed")
return []
}
const isRepo = await checkGitRepo(cwd)
if (!isRepo) {
console.error("Not a git repository")
return []
}
// Search commits by hash or message, limiting to 10 results
const { stdout } = await execAsync(
`git log -n 10 --format="%H%n%h%n%s%n%an%n%ad" --date=short ` + `--grep="${query}" --regexp-ignore-case`,
{ cwd },
)
let output = stdout
if (!output.trim() && /^[a-f0-9]+$/i.test(query)) {
// If no results from grep search and query looks like a hash, try searching by hash
const { stdout: hashStdout } = await execAsync(
`git log -n 10 --format="%H%n%h%n%s%n%an%n%ad" --date=short ` + `--author-date-order ${query}`,
{ cwd },
).catch(() => ({ stdout: "" }))
if (!hashStdout.trim()) {
return []
}
output = hashStdout
}
const commits: GitCommit[] = []
const lines = output
.trim()
.split("\n")
.filter((line) => line !== "--")
for (let i = 0; i < lines.length; i += 5) {
commits.push({
hash: lines[i],
shortHash: lines[i + 1],
subject: lines[i + 2],
author: lines[i + 3],
date: lines[i + 4],
})
}
return commits
} catch (error) {
console.error("Error searching commits:", error)
return []
}
}
export async function getCommitInfo(hash: string, cwd: string): Promise<string> {
try {
const isInstalled = await checkGitInstalled()
if (!isInstalled) {
return "Git is not installed"
}
const isRepo = await checkGitRepo(cwd)
if (!isRepo) {
return "Not a git repository"
}
// Get commit info, stats, and diff separately
const { stdout: info } = await execAsync(`git show --format="%H%n%h%n%s%n%an%n%ad%n%b" --no-patch ${hash}`, {
cwd,
})
const [fullHash, shortHash, subject, author, date, body] = info.trim().split("\n")
const { stdout: stats } = await execAsync(`git show --stat --format="" ${hash}`, { cwd })
const { stdout: diff } = await execAsync(`git show --format="" ${hash}`, { cwd })
const summary = [
`Commit: ${shortHash} (${fullHash})`,
`Author: ${author}`,
`Date: ${date}`,
`\nMessage: ${subject}`,
body ? `\nDescription:\n${body}` : "",
"\nFiles Changed:",
stats.trim(),
"\nFull Changes:",
].join("\n")
const output = summary + "\n\n" + diff.trim()
return truncateOutput(output, GIT_OUTPUT_LINE_LIMIT)
} catch (error) {
console.error("Error getting commit info:", error)
return `Failed to get commit info: ${error instanceof Error ? error.message : String(error)}`
}
}
export async function getWorkingState(cwd: string): Promise<string> {
try {
const isInstalled = await checkGitInstalled()
if (!isInstalled) {
return "Git is not installed"
}
const isRepo = await checkGitRepo(cwd)
if (!isRepo) {
return "Not a git repository"
}
// Get status of working directory
const { stdout: status } = await execAsync("git status --short", { cwd })
if (!status.trim()) {
return "No changes in working directory"
}
// Get all changes (both staged and unstaged) compared to HEAD
const { stdout: diff } = await execAsync("git diff HEAD", { cwd })
const lineLimit = GIT_OUTPUT_LINE_LIMIT
const output = `Working directory changes:\n\n${status}\n\n${diff}`.trim()
return truncateOutput(output, lineLimit)
} catch (error) {
console.error("Error getting working state:", error)
return `Failed to get working state: ${error instanceof Error ? error.message : String(error)}`
}
}
/**
* Gets git status output with configurable file limit
* @param cwd The working directory to check git status in
* @param maxFiles Maximum number of file entries to include (0 = disabled)
* @returns Git status string or null if not a git repository
*/
export async function getGitStatus(cwd: string, maxFiles: number = 20): Promise<string | null> {
try {
const isInstalled = await checkGitInstalled()
if (!isInstalled) {
return null
}
const isRepo = await checkGitRepo(cwd)
if (!isRepo) {
return null
}
// Use porcelain v1 format with branch info
const { stdout } = await execAsync("git status --porcelain=v1 --branch", { cwd })
if (!stdout.trim()) {
return null
}
const lines = stdout.trim().split("\n")
// First line is always branch info (e.g., "## main...origin/main")
const branchLine = lines[0]
const fileLines = lines.slice(1)
// Build output with branch info and limited file entries
const output: string[] = [branchLine]
if (maxFiles > 0 && fileLines.length > 0) {
const filesToShow = fileLines.slice(0, maxFiles)
output.push(...filesToShow)
// Add truncation notice if needed
if (fileLines.length > maxFiles) {
output.push(`... ${fileLines.length - maxFiles} more files`)
}
}
return output.join("\n")
} catch (error) {
console.error("Error getting git status:", error)
return null
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

开源 VS Code AI 自主编程智能体插件,仓库结构:采用 pnpm + turbo 多包工程,包含 apps、packages、webview-ui、src 等核心目录,配套完整工程规范文件(husky、prettier、nvmrc、dockerignore 等),支持多语言国际化、自动化测试、打包分发。
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/devai/Roo-Code.git
git@gitee.com:devai/Roo-Code.git
devai
Roo-Code
Roo-Code
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /