Skip to content

Add a grut status command for scriptable repo state#319

Open
jongio wants to merge 1 commit into
mainfrom
idea/grut-status-command
Open

Add a grut status command for scriptable repo state#319
jongio wants to merge 1 commit into
mainfrom
idea/grut-status-command

Conversation

@jongio

@jongio jongio commented Jul 12, 2026

Copy link
Copy Markdown
Owner

What

Adds a grut status subcommand that prints a summary of the current repository state, with a --json flag for scripting.

Text output shows the branch, upstream tracking (ahead/behind), and the staged, unstaged, untracked, and conflicted files. JSON output is a stable document with the same information plus counts, so tools and scripts can parse it without scraping the human format.

$ grut status
On branch main
Tracking origin/main [ahead 1]
Staged (1):
  M cmd/status.go
Untracked (1):
  ? notes.txt

$ grut status --json
{
  "branch": "main",
  "upstream": "origin/main",
  "ahead": 1,
  "behind": 0,
  "detached": false,
  "clean": false,
  "staged": [{ "path": "cmd/status.go", "status": "M" }],
  "unstaged": [],
  "untracked": ["notes.txt"],
  "conflicted": [],
  "counts": { "staged": 1, "unstaged": 0, "untracked": 0, "conflicted": 0 }
}

How

  • New StatusWithBranch method on the git client returns the branch header and file entries from a single porcelain v2 invocation, so the command does not run git status twice.
  • buildStatusReport classifies entries into staged, unstaged, untracked, and conflicted buckets. A file that is changed in both the index and the worktree appears in both staged and unstaged.
  • Detached HEAD is detected from the porcelain header and reported as such.

Testing

  • Unit tests for classification, clean and detached states, text output sections, and JSON round-trip.
  • Integration test that runs the command against a real temporary repo (guarded on git being available).
  • go build ./..., go vet ./..., and gofumpt all clean.

Closes #314

Add a `grut status` subcommand that prints a summary of the working tree:
current branch, upstream tracking with ahead/behind counts, and the staged,
unstaged, untracked, and conflicted files. Pass --json for a stable
machine-readable document that scripts and other tools can parse.

The command reuses the existing porcelain v2 parsing. A new
StatusWithBranch git client method returns the branch header and file
entries from a single git invocation so callers do not run status twice.

Closes #314

Co-authored-by: Copilot App <[email protected]>
@jongio jongio added the idea Feature idea from the idea pipeline label Jul 12, 2026
@jongio jongio self-assigned this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

idea Feature idea from the idea pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a grut status command

1 participant