MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / GetGitContext

Function GetGitContext

agentContext/builder.go:248–289  ·  view source on GitHub ↗
(cwd string, timeout float32, compact bool)

Source from the content-addressed store, hash-verified

246 if hasCurrentName {
247 sections = append(sections, PromptSection{currentName, strings.TrimSpace(strings.Join(currentLines, "\n")), false})
248 }
249 currentName = strings.TrimSpace(strippedLine[len("[SECTION: ") : len(strippedLine)-1])
250 currentLines = []string{}
251 hasCurrentName = true
252 continue
253 }
254 currentLines = append(currentLines, line)
255 }
256 if hasCurrentName {
257 sections = append(sections, PromptSection{
258 currentName,
259 strings.TrimSpace(strings.Join(currentLines, "\n")),
260 false,
261 })
262 }
263 return sections, nil
264}
265
266func GetGitContext(cwd string, timeout float32, compact bool) string {
267 if hook := currentPromptHooks().GitContext; hook != nil {
268 return hook(cwd, timeout, compact)
269 }
270 if timeout == 0 {
271 timeout = 3.0
272 }
273 if _, err := exec.LookPath("git"); err != nil {
274 return ""
275 }
276 var lines []string
277 if output, ok := runGitCommand(cwd, secondsDuration(timeout), "branch", "--show-current"); ok {
278 branch := strings.TrimSpace(output)
279 if branch != "" {
280 lines = append(lines, "Git branch: "+branch)
281 }
282 }
283 if !compact {
284 if output, ok := runGitCommand(cwd, secondsDuration(timeout), "log", "--oneline", "-5"); ok {
285 output = strings.TrimSpace(output)
286 if output != "" {
287 lines = append(lines, "Recent commits:")
288 for _, commitLine := range strings.Split(output, "\n") {
289 lines = append(lines, " "+commitLine)
290 }
291 }
292 }

Callers 2

buildSystemPromptMethod · 0.92
BuildBudgetGitSectionFunction · 0.85

Calls 3

currentPromptHooksFunction · 0.85
runGitCommandFunction · 0.85
secondsDurationFunction · 0.85

Tested by

no test coverage detected