BranchBase
branch_base
is a Ruby gem to synchronize data from a Git repository into a SQLite database. It provides a CLI to easily build and store the data, including commits, branches, and file changes, into a SQLite database.
You can now easily run, any kind of analytics on your Git directory using the SQLite database.
Features β¨
- Synchronize Git repository data into a SQLite database.
- Query commit history, branch details, and file changes using SQL.
- Easy-to-use CLI for quick setup and execution.
- πΈ Check out the example below on how you can use
branch_base
to create a Spotify themed Git Wrapped using SQL
Usage π οΈ
After installation, you can use branch_base
to generate a SQLite Database of a Git repository:
$ branch_base sync ~/src/rails
Git wrapped πΈ
Easily generate a Git wrapped with some built-queries and style using branch_base
$ branch_base git-wrapped ~/src/rails
2023-12-03 11:40:50 -0500: INFO - BranchBase: Generating Git wrapped for /Users/shayon/src/rails...
2023-12-03 11:40:53 -0500: INFO - BranchBase: Git wrapped JSON stored in /Users/shayon/src/rails/git-wrapped.json
2023-12-03 11:40:53 -0500: INFO - BranchBase: Git wrapped HTML stored in /Users/shayon/src/rails/git-wrapped.html
Example SQL Queries π
Once your repository data is synchronized into a SQLite database, you can run various SQL queries to analyze the data. Here are some examples:
-
List all commits:
SELECT * FROM commits;
-
Find commits by a specific author:
SELECT * FROM commits WHERE author = 'John Doe';
-
Get the number of commits in each branch:
SELECT branches.name, COUNT(commits.commit_hash) as commit_count FROM branches JOIN commits ON branches.head_commit = commits.commit_hash GROUP BY branches.name;
-
List files changed in a specific commit:
SELECT files.file_path FROM commit_files JOIN files ON commit_files.file_id = files.file_id WHERE commit_files.commit_hash = 'ABC123';
-
Count of Commits per Author
SELECT author, COUNT(*) as commit_count FROM commits GROUP BY author ORDER BY commit_count DESC;
-
Authors Who Have Worked on a Specific File
SELECT files.file_path, commits.author, COUNT(*) as times_contributed FROM commits JOIN commit_files ON commits.commit_hash = commit_files.commit_hash JOIN files ON commit_files.file_id = files.file_id WHERE files.file_path LIKE '%connection_adapters/sqlite%' GROUP BY files.file_path, commits.author ORDER BY times_contributed DESC;
Installation π₯
Via RubyGems π
You can install branch_base
directly using RubyGems:
$ gem install branch_base
Via Docker π³
branch_base
is also available as a Docker image, which can be used to run the tool without setting up a Ruby environment:
$ docker pull shayonj/branch_base:latest
To use branch_base
with Docker, you can mount your Git repository as a volume:
$ docker run -v /repo/path:/repo shayonj/branch_base sync /repo
This command will create a SQLite database with the repository's data in the path where the command is called from
Database Schema πΊοΈ
The SQLite database of the follow tables:
repositories βββββββββββββββββββββββ¬βββββββββββββββββ files
β β
ββ commits ββββββ commit_files βββ
β β
β ββ branch_commits ββ branches
β β
β ββ commit_parents
β
ββ files (via latest_commit in commits)
In this schema:
-
repositories
has direct relationships withcommits
andfiles
viarepo_id
-
commits
is central, connecting tocommit_files
,branch_commits
, andcommit_parents
, viacommit_hash
-
commit_files
provides a link betweencommits
andfiles
. -
branch_commits
joinsbranches
withcommits
, viabranch_id
andcommit_hash
-
branches
are linked back torepositories
. -
files
also connects back tocommits
through thelatest_commit
.
Contributing π€
Contributions to branch_base
are welcome!
License π
Distributed under the MIT License. See LICENSE
for more information.
Development π»
- Install ruby
3.1.4
using RVM (instruction) -
bundle exec rspec
for specs