Format git context as a string for the systemContext.gitStatus key. Mirrors TS getGitStatus output format from context.ts.
(ctx: GitContextSnapshot)
| 195 | # --------------------------------------------------------------------------- |
| 196 | |
| 197 | def format_git_status(ctx: GitContextSnapshot) -> str: |
| 198 | """ |
| 199 | Format git context as a string for the systemContext.gitStatus key. |
| 200 | |
| 201 | Mirrors TS getGitStatus output format from context.ts. |
| 202 | """ |
| 203 | if not ctx.available: |
| 204 | return "" |
| 205 | |
| 206 | parts: list[str] = [] |
| 207 | parts.append("Git repository detected.") |
| 208 | |
| 209 | if ctx.branch: |
| 210 | parts.append(f"Current branch: {ctx.branch}") |
| 211 | if ctx.default_branch: |
| 212 | parts.append(f"Default branch: {ctx.default_branch}") |
| 213 | if ctx.user_name: |
| 214 | parts.append(f"User: {ctx.user_name}") |
| 215 | |
| 216 | if ctx.status: |
| 217 | parts.append(f"\nStatus:\n{ctx.status}") |
| 218 | if ctx.status_truncated: |
| 219 | parts.append("(Status output was truncated)") |
| 220 | else: |
| 221 | parts.append("\nWorking tree clean.") |
| 222 | |
| 223 | if ctx.recent_commits: |
| 224 | parts.append(f"\nRecent commits:\n{ctx.recent_commits}") |
| 225 | |
| 226 | return "\n".join(parts) |