A mini Git in Python
The problem
Write a small version control system in Python that stores real Git objects, so that its ids match git hash-object, and supports the everyday commands.
Requirements
- Store blobs, trees and commits in an object folder, named by their SHA-1 ids exactly as Git computes them
- Support init, add, commit, status (short format), log, branch, switch and diff
- Keep refs and HEAD as files, including a detached HEAD
- Merge with fast-forward and file-level three-way merges, reporting conflicts
- Check every object id against the real git for a sample repository
Technologies
- Python
- hashlib
- Files and folders
- Graphs
Step by step
- Implement hash-object and an object store, and compare ids with git hash-object.
- Add the index, add and commit, writing tree and commit objects.
- Add status, log and diff using the algorithms from the course.
- Add branches, HEAD and switching, refusing to overwrite local changes.
- Add merge-base and three-way merging, then test on example histories.
Expected result
A working mini Git whose objects real Git can read, built from the ideas in the course.
How it is evaluated
- Blob, tree and commit ids match real Git on test files
- Status codes and logs match Git's output for the same history
- Merges handle fast-forwards, clean merges and conflicts
- Every command has tests
Ways to improve it
- Compress objects with zlib, so git cat-file can read your object folder
- Add rebase and a reflog
- Add a line-level three-way merge with conflict markers