Skip to content
strange-exePublic

About

MiniGit is a console-based C++ project that demonstrates version control through commits, history, checkout, and rollback operations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MiniGit: A Lightweight Version Control System Using C++ and Data Structures

Language Build Course

Team Blaze Β· DSCPP-III-2026-T296 Β· CSE (AI&ML)
Department of Computer Science & Engineering β€” Graphic Era (Deemed to be University)


πŸ“Œ Overview

MiniGit is a lightweight, local, terminal-based version control system implemented in C++. Designed as an educational version control system, MiniGit demystifies core VCS conceptsβ€”repository initialization, staging areas, ignore rule management, and commit workflowsβ€”while directly applying foundational computer science data structures such as Tries (Prefix Trees), an ordered set, a double-ended queue (undo/redo), and a doubly linked list (commit log).


πŸ—οΈ System Architecture

MiniGit follows a modular 5-layer architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 1. CLI Interface & Argument Parser                      β”‚
β”‚    (Tokenizes input, validates flags: -r, -v, ., etc.)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2. Command Handler & Dispatcher (Abhinesh's Module)     β”‚
β”‚    (Maps commands -> operations; handles status codes)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 3. Repository & Staging Manager                         β”‚
β”‚    (.minigit/ structure, index persistence, undo/redo)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 4. Ignore Engine (Trie Data Structure)                  β”‚
β”‚    (Dual Prefix Trees: Path Trie & Reversed Ext Trie)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 5. Storage Layer (File I/O)                             β”‚
β”‚    (.minigit/objects, .minigit/index, .minigit/HEAD)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ‘₯ Module Breakdown

Abhinesh (Team Lead) β€” CLI, Dispatcher & Repository Setup

  • minigit init: Creates .minigit/ (objects/, refs/heads/, HEAD = ref: refs/heads/main, index) and .minigitignore. Re-running it never overwrites existing data, and every failed write is reported.
  • Table-Driven Command Dispatcher: One table row per command holds its name, aliases, usage forms and handler. minigit help, minigit help <command>, minigit <command> --help and the usage printed on wrong arguments are all generated from it, so they cannot go out of date.
  • Typo Suggestions: An unknown command is matched to the closest real one by Levenshtein edit distance (minigit comit β†’ The most similar command is commit).
  • Status & Error Mapper: Turns result structs (InitResult, AddResult, IgnoreResult, CommitResult, LogResult) into messages and exit codes (0 = success, 1 = error).
  • Ignore CLI Interface: Validates ignore, ignore -r and ignore -v input; rejects empty patterns and anything outside the repository (.., absolute paths, drive letters).
  • First-Run Self-Installation: Copies the executable into the user's PATH on first run, and refreshes that copy when a newer build is run.

Sparsh β€” Trie & Staging Area Module

  • Trie (Prefix Tree) Engine: Dual-Trie architecture for fast $O(L)$ pattern matching without disk scans.
  • Staging Area (.minigit/index): Holds one normalized relative path per line with duplicate staging prevention.
  • Add Operations: Supports single file tracking (add <file>), batch repository staging (add .), and unstaging (remove <file|dir|.>).

Krish β€” Commit & Undo/Redo Module

  • minigit commit: Saves each staged file's content under .minigit/objects/<id>/snapshot/, writes metadata (parent, timestamp, author, message, files) and moves HEAD. The commit id is a SHA-1 of that content.
  • Undo / Redo (std::deque): Two deques of repository states. A new commit clears the redo deque; the undo deque is capped at 20 entries with pop_front(). Persisted in .minigit/history.

Snehil β€” Commit Log Module

  • minigit log: Rebuilds the history from HEAD by following parent links into a doubly linked list, then walks it backward (newest first) or forward with --reverse.

🌳 Data Structures Applied

1. Dual Trie (Prefix Tree) β€” .minigitignore

Used for instant, deterministic pattern matching to block ignored files from staging:

  • Forward Path Trie: Stores exact file paths (secret.txt) and directory rules (build/). Traverses path tokens in $O(L)$ time.
  • Reversed Extension Trie: Stores wildcard extension patterns (e.g. *.log is stored as reversed key gol.). When evaluating a filename, its reversed extension is queried in $O(E)$ time.
  • Line Number Indexing: Every terminal Trie node stores the 1-based line number of the matching rule from .minigitignore, allowing instant rule tracking during verification.

2. Staging Index (Ordered Set & Flat File)

  • Maintains staged file paths in .minigit/index (one path per line).
  • Held in memory as std::set (a red-black tree): $O(\log n)$ duplicate staging prevention and status checks, and entries stay sorted so the index file has a stable order.

3. Double-Ended Queue β€” undo / redo

  • std::deque gives $O(1)$ push_back/pop_back for undo and redo, and $O(1)$ pop_front to drop the oldest state once the 20-entry history limit is reached.

4. Doubly Linked List β€” commit log

  • Each CommitNode links to the older and newer commit, so log and log --reverse are both a single $O(n)$ walk from one end of the list.

πŸ’» Supported Commands & Usage

Command Action / Dispatcher Function Description
minigit init initRepo() Initializes a local repository structure (.minigit/, HEAD, refs/heads/, index)
minigit add <file|dir> addFile(path) Stages a file, or every non-ignored file in a directory
minigit add . addAll() Recursively stages all unignored files in the repository
minigit add -v <file> addVerify(path) Verifies if file is staged (prints '<file>' is staged via IS_STAGED)
minigit remove <file|dir> removeFile(path) Unstages a file, or every staged file in a directory, without touching the working tree
minigit remove . removeFile(".") Clears all staged files from the staging area
minigit ignore IgnoreManager::lines() Lists the rules in .minigitignore with line numbers
minigit ignore <pattern> ignoreAdd(pattern) Validates and appends <pattern> to .minigitignore and updates the Trie
minigit ignore -r <pattern> ignoreRemove(pattern) Removes <pattern> from .minigitignore (or reports "not present")
minigit ignore -v <path> ignoreVerify(path) Checks if <path> is ignored; returns exact rule and line number
minigit commit "<message>" / commit -m "<message>" commitRepo(message) Records the staged files as a new commit and clears the index
minigit commit undo / undo undoCommit() Moves HEAD back one commit and restores its staged files
minigit commit redo / redo redoCommit() Re-applies the last undone commit
minigit log [--reverse] showLog(reverse) Shows the commit history, newest first (oldest first with --reverse)
minigit help [<command>] command table Lists every command, or the usage of one (minigit <command> --help also works)
minigit install CLI::install() Manually copies minigit into the user's PATH
minigit uninstall CLI::uninstall() Removes minigit from user PATH

πŸ› οΈ Build & Test Instructions

Prerequisites

  • Compiler: g++ (GCC 6.3+ or modern Clang/MSVC, supports C++14/C++17)
  • Build Tool: GNU make or mingw32-make

Building the Project

From the repository root:

# Compile standalone executable minigit
make all

Running the Test Suites

The project includes automated test suites covering all modules:

# Run all unit tests
make test

Test coverage includes:

  • test_trie: Forward/reversed Trie pattern matching, wildcard extensions, and node pruning.
  • test_add: Staging, duplicate prevention, ignore enforcement, and persistence.
  • test_init: Repository creation, metadata structure, and reinitialization handling.
  • test_cli: Full CLI dispatching, argument validation, generated help, typo suggestions, and the IS_STAGED print case.
  • test_commit: Commit ids and metadata, snapshots, undo/redo and the history limit, multi-line messages.
  • test_commitlog: The doubly linked list on its own (insert, find, cursor movement).
  • test_log: log / log --reverse over real commits, after undo, and through the CLI.

Cleaning Build Files

make clean

⚑ Global Execution (First-Run Auto-Install)

By default, PowerShell and Unix terminals restrict running local executables without prefixing .\ or ./.

MiniGit includes built-in zero-config self-installation:

  • The first time .\minigit is run on a Windows 10/11 system, it automatically copies itself into %LOCALAPPDATA%\Microsoft\WindowsApps\minigit.exe.
  • Because this directory is already in the user's PATH by default and requires no administrator privileges, you can immediately run:
    minigit init
    minigit add .
    minigit ignore -v secret.txt
    from any folder or terminal window on your machine.

πŸ“‚ Repository Structure

MiniGit-CLI/
β”œβ”€β”€ .gitignore               # Ignores build artifacts, temporary test files, and local repo state
β”œβ”€β”€ LICENSE                  # MIT License
β”œβ”€β”€ Makefile                 # Top-level build orchestration
β”œβ”€β”€ README.md                # Project documentation
β”œβ”€β”€ Reports/                 # Phase evaluation documentation
β”‚   β”œβ”€β”€ ppt.pdf              # Phase-I presentation slides
β”‚   └── report.pdf           # Phase-I project proposal & architecture report
└── module/                  # Core source code & unit tests
    β”œβ”€β”€ Makefile             # Module compilation and test runners
    β”œβ”€β”€ include/             # Header declarations
    β”‚   β”œβ”€β”€ AddCommand.h     # add / add . / add -v / remove interface
    β”‚   β”œβ”€β”€ CLI.h            # CLI parser, dispatcher, and status mapper
    β”‚   β”œβ”€β”€ CommitCommand.h  # commit / undo / redo interface
    β”‚   β”œβ”€β”€ CommitHistory.h  # Undo/redo deques (.minigit/history)
    β”‚   β”œβ”€β”€ CommitLog.h      # Doubly linked list over commits
    β”‚   β”œβ”€β”€ CommitNode.h     # One commit (list node)
    β”‚   β”œβ”€β”€ IgnoreManager.h  # .minigitignore parser & Trie bridge
    β”‚   β”œβ”€β”€ InitCommand.h    # initRepo interface
    β”‚   β”œβ”€β”€ LogCommand.h     # log / log --reverse interface
    β”‚   β”œβ”€β”€ PathUtils.h      # Path normalization & safety utilities
    β”‚   β”œβ”€β”€ StagingArea.h    # .minigit/index persistence manager
    β”‚   β”œβ”€β”€ Trie.h           # Pure Prefix Tree data structure
    β”‚   β”œβ”€β”€ filesystem       # Cross-compiler filesystem wrapper
    β”‚   └── ghc/             # Header-only standard filesystem implementation
    β”œβ”€β”€ src/                 # Implementation files
    β”‚   β”œβ”€β”€ AddCommand.cpp
    β”‚   β”œβ”€β”€ CLI.cpp          # Command table, dispatcher and output
    β”‚   β”œβ”€β”€ CommitCommand.cpp
    β”‚   β”œβ”€β”€ CommitHistory.cpp
    β”‚   β”œβ”€β”€ CommitLog.cpp
    β”‚   β”œβ”€β”€ IgnoreManager.cpp
    β”‚   β”œβ”€β”€ InitCommand.cpp
    β”‚   β”œβ”€β”€ LogCommand.cpp
    β”‚   β”œβ”€β”€ StagingArea.cpp
    β”‚   β”œβ”€β”€ Trie.cpp
    β”‚   β”œβ”€β”€ main.cpp         # Production CLI entry point
    β”‚   β”œβ”€β”€ main_demo.cpp    # Standalone demo interface (add/ignore)
    β”‚   └── main_demo_log.cpp  # Standalone demo interface (log)
    └── tests/               # Automated unit tests
        β”œβ”€β”€ test_add.cpp
        β”œβ”€β”€ test_cli.cpp
        β”œβ”€β”€ test_commit.cpp
        β”œβ”€β”€ test_commitlog.cpp
        β”œβ”€β”€ test_init.cpp
        β”œβ”€β”€ test_log.cpp
        └── test_trie.cpp

πŸ“„ License

MiniGit is released under the MIT License.

About

MiniGit is a console-based C++ project that demonstrates version control through commits, history, checkout, and rollback operations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages