Skip to content

20260404 211557 cli commit export#2

Open
locchh wants to merge 8 commits intomasterfrom
20260404-211557-cli-commit-export
Open

20260404 211557 cli commit export#2
locchh wants to merge 8 commits intomasterfrom
20260404-211557-cli-commit-export

Conversation

@locchh
Copy link
Copy Markdown
Owner

@locchh locchh commented Apr 4, 2026

PR Description

Summary

This PR extends cex with headless CLI export capabilities, reducing reliance on the TUI for inspecting and archiving commit history. All changes are confined to app.py (single-file architecture) with no new dependencies.

New flags

  • --show <sha> — Export full details of a single commit (metadata, file stats, unified diff) to a .txt file. Accepts short or full SHAs.
  • --range <base> <target> — Export all commits in a linear ancestry range (git log base..target), one .txt file per commit with Exporting N/total… progress on stderr. Also supports --range <sha> --depth N to export the last N ancestors.
  • --out <path> — Unified output folder flag for all headless modes (--show, --range, --compare, --pr). Defaults to /tmp, created automatically if missing.
  • --export --out <path> — Extended existing --export to optionally write the commit graph to a plain-text file (uses git log --graph directly) instead of printing to stdout.

Output filename format

Commit export files follow: <YYYYMMDD>_<short-sha>_<slug>.txt
Example: 20260404_f291787_add-safety-guardrails-to-claude-md.txt

Technical highlights

  • _resolve_sha() — uses git rev-parse to resolve short or full SHAs robustly
  • _slugify() — stdlib-only slug generator for filenames
  • _write_commit_export() — writes commit header + diff summary + changed files + full unified diff; uses transient -c extensions.partialclone=origin flags so git show lazy-fetches blobs from the promisor remote without modifying the repo config (which would break Dulwich)
  • _write_export() — gained out_dir param (default ".") so --compare and --pr also respect --out
  • _export() — simplified to run git log --graph directly via subprocess; --color=always for stdout, --no-color for file

Test plan

  • uv run cex locchh/commit-explorer --show <sha> --out /tmp — verify .txt file created with metadata and full diff
  • uv run cex locchh/commit-explorer --range <base> <target> --out /tmp — verify one file per commit, progress on stderr
  • uv run cex locchh/commit-explorer --range <sha> --depth 5 --out /tmp — verify 5 files exported
  • uv run cex locchh/commit-explorer --show 0000000 — verify non-zero exit and error on stderr
  • uv run cex locchh/commit-explorer --export --out . — verify plain-text graph file written
  • uv run cex locchh/commit-explorer --export — verify coloured graph still prints to stdout
  • uv run cex locchh/commit-explorer --compare master <branch> — verify report still written (no regression)

locchh added 8 commits April 4, 2026 21:21
Add comprehensive specification for new CLI export functionality:
- Individual commit export with --show <sha>
- Commit range export with --range <base> <target>
- Depth-based export with --range <target> --depth N
- Unified --out flag for all headless commands
- Automatic output directory creation
- Progress reporting and error handling
- Quality checklist with validation criteria
Add detailed technical specification and planning documents:
- CLI flag contracts and interface definitions
- Data model for commit export functionality
- Implementation plan with task breakdown
- Quickstart guide with usage examples
- Technical research with key design decisions
- Dulwich integration strategy for SHA resolution and range walking
Add comprehensive task breakdown for CLI export feature:
- 18 detailed implementation tasks grouped by user story
- Phase-based approach with setup, foundational, and story-specific tasks
- Parallel execution opportunities and dependency mapping
- MVP-first strategy with incremental delivery
- All tasks target single-file architecture (app.py only)
- No new dependencies required, uses existing Dulwich capabilities
Complete implementation of CLI export features:
- Add --show flag for single commit export with metadata and diff
- Add --range flag for commit range export with progress reporting
- Add unified --out flag for all headless modes
- Update CLI.md with new flags and usage examples
- Complete all 18 implementation tasks across 3 user stories
- Support Dulwich-based SHA resolution and range walking
- Maintain backward compatibility for existing --compare/--pr modes
- Replace hardcoded branch name with placeholder in README installation instructions
- Add _resolve_sha() helper function using git rev-parse for robust SHA resolution
- Update git configuration to use transient -c flags for partial clone support
- Improve error handling and timeout for git operations
- Use full SHA resolution consistently across --show and --range commands
Replace hardcoded branch name with placeholder <branch-name>
in installation instructions to make documentation more
maintainable and applicable to any branch.
- Replace Rich console output with native git log --graph for better performance
- Add optional out_dir parameter to _export for file output support
- Implement smart output directory resolution:
  * --export with --out → write timestamped file to specified folder
  * --export without --out → colored output to stdout (existing behavior)
  * All other modes without --out → default to /tmp
- Update all headless functions to use unified out_dir parameter
- Maintain backward compatibility for existing --export behavior
- Replace Rich console rendering with native git log --graph
- Add support for both colored stdout and file output
- Implement proper filename generation for export files
- Update argument handling for flexible output modes
- Maintain backward compatibility for existing --export behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant