Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion git_why.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ def cmd_log(args):
continue
if args.with_reason and "Why" not in tr:
continue

if args.json:
obj = {"commit": rec["short"], "subject": rec["subject"], "date": rec["date"]}
for k, v in tr.items():
key = "why" if k == "Why" else "why_" + k[4:].lower().replace("-", "_")
obj[key] = v
print(json.dumps(obj, ensure_ascii=False))
first = False
continue

if not first:
print()
first = False
Expand All @@ -257,7 +267,7 @@ def cmd_log(args):
meta = [f"{LABEL[k]}: {tr[k]}" for k in ("Why-Agent", "Why-Session", "Why-Spec") if tr.get(k)]
if meta:
print(" " + paint(" ".join(meta), "dim"))
if first:
if first and not args.json:
print("no matching commits")
return 0

Expand Down Expand Up @@ -445,6 +455,7 @@ def main():
sp.add_argument("--session", help="only commits whose Why-Session contains this")
sp.add_argument("--spec", help="only commits whose Why-Spec contains this")
sp.add_argument("--with-reason", action="store_true", help="hide commits with no Why:")
sp.add_argument("--json", action="store_true", help="emit NDJSON (one object per commit) instead of the text view")
sp.set_defaults(fn=cmd_log)

sp = sub.add_parser("export", help="NDJSON of every recorded reason")
Expand Down
3 changes: 3 additions & 0 deletions test/smoke.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ gw helper.py | grep -q "split out of core" || fail "git why <path>"
gw log | grep -q "split out of core" || fail "git why log"
gw log --agent claude | grep -q "split out of core" || fail "git why log --agent"
gw log --agent nope | grep -q "no matching commits" || fail "git why log --agent filter"
gw log --json | python3 -c "import sys,json; [json.loads(l) for l in sys.stdin if l.strip()]" \
|| fail "git why log --json is not valid NDJSON"
gw log --json | grep -q '"why_agent": "claude-sonnet-5"' || fail "log --json missing why_agent"
gw export | python3 -c "import sys,json; [json.loads(l) for l in sys.stdin if l.strip()]" \
|| fail "git why export is not valid NDJSON"
gw export | grep -q '"why_agent": "claude-sonnet-5"' || fail "export missing why_agent"
Expand Down
Loading