Git Commit Stats CLI Tool
Build a Swift command-line tool that analyzes a Git repository's history and prints an easy-to-read report: who commits the most, which days of the week and hours are busiest, how activity changes month by month, and which commits were the largest. It runs git log through Foundation's Process API with a custom format that's easy to parse, so it works on any repository on your computer. Options let you choose the repository, a date range and one author. You'll learn Swift Argument Parser, running other programs from Swift, parsing text output reliably, grouping and sorting data with Swift collections, working with dates, and formatting terminal output.
- Estimate
- ~9h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Foundation · ArgumentParser
Project roadmap
- 01
Set up the package
~1hCreate a package with swift package init --type executable and add Swift Argument Parser. Define options: --repo (default: the current folder), --since and --until dates, --author, --top (default 10) and --json. Check that the folder is a Git repository (git rev-parse) and show a clear error when it isn't. Done when: gitstats --help shows every option.
- 02
Run git log
~1.5hRun git log through Process with a format using unusual separators that won't appear in commit messages, such as --pretty=format:'%x1e%H%x1f%an%x1f%ae%x1f%aI%x1f%s' plus --numstat for lines added and removed per file. Read the output from a Pipe and check the exit status, showing git's error message when it fails. Done when: the tool captures the log of a real repository.
- 03
Parse the commits
~2hSplit the output into records and fields using the separators, parse the date with ISO8601DateFormatter, and sum the numstat lines into lines added and removed per commit (treating binary files, shown as -, as 0). Create a Commit struct. Group authors by email so the same person with different name spellings counts once. Done when: the number of parsed commits matches git rev-list --count.
- 04
Compute statistics
~1.5hUsing Dictionary(grouping:by:) and sorting, compute: commits and lines changed per author, commits per weekday and per hour (in local time), commits per month, and the largest commits by lines changed, excluding merge commits. Done when: the statistics for a small test repository match what you count by hand.
- 05
Print the report
~1.5hPrint aligned tables with padding, text bar charts for weekdays and hours (█ characters scaled to the maximum), and colors with ANSI codes only when the output is a terminal (isatty). With --json, print all statistics as JSON using Codable. Done when: the report is easy to read on a real repository, and --json produces valid JSON.
- 06
Test it
~1.5hWrite tests that parse saved git log output (including binary files, merge commits, and messages with special characters), and an integration test that creates a temporary repository with a few commits by different authors and dates (using git commands with GIT_AUTHOR_DATE) and checks the statistics. Done when: swift test passes.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack