(cwd string, timeout float32, compact bool)
| 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 | |
| 266 | func 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 | } |
no test coverage detected