Skip to content

Command-line tool that analyzes local git repositories and creates a text file containing repository content optimized for sharing with Large Language Models (LLMs).

License

Notifications You must be signed in to change notification settings

ElshadHu/RepositoryContextPackager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RepositoryContextPackager

Command-line tool that analyzes local git repositories and creates a text file containing repository content optimized for sharing with Large Language Models (LLMs).This tool helps developers efficiently share their codebase context with Ai tools such as ChatGPT via collection repository information,project structure and file contents into a single, well-designed document.

Features

  • Git Integration - Automatically detects Git repository information (commit, branch, author, date)
  • Smart File Discovery - Recursively analyzes directories and individual files
  • Multiple File Type Support - Handles C/C++, JavaScript, Python, Java, TypeScript, and configuration files
  • Error Handling - Gracefully handles permission errors and inaccessible files
  • File Size Management - Automatically truncates large files (>16KB) with truncation notices
  • Flexible Input - Supports analyzing directories, individual files, or combinations
  • Include/Exclude Feature Supports including or excluding specific folders or files
  • Config File Support - Automatically loads options from config.toml, allowing CLI overrides for flexible and maintainable workflows

Prerequisites

  • CMake 3.20 or higher
  • C++17 compatible compiler
  • Git(for repository analysis features)

Windows

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat

2. Build the project

Clone this repository

git clone https://github.com/ElshadHu/RepositoryContextPackager
cd RepositoryContextPackager
# Method 1: Using environment variable (recommended)
cmake -B build -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake"
cmake --build build

# Method 2: Direct path (if vcpkg is in parent directory)
cmake -B build -DCMAKE_TOOLCHAIN_FILE="..\vcpkg\scripts\buildsystems\vcpkg.cmake"
cmake --build build

# Method 3: Without specifying toolchain (if vcpkg is configured globally)
cmake -B build
cmake --build build

Linux

1.
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
chmod +x ./bootstrap-vcpkg.sh
./bootstrap-vcpkg.sh

2.
set VCPKG_ROOT=%CD%
chmod  +x ./vcpkg
./vcpkg install libgit2

3.
git clone   https://github.com/ElshadHu/RepositoryContextPackager
cd RepositoryContextPackager

cmake -G "Ninja" -B build
cmake --build build

macOS

# Install dependencies
brew install cmake libgit2 pkg-config git

# Build
git clone https://github.com/ElshadHu/RepositoryContextPackager
cd RepositoryContextPackager
cmake -B build
cmake --build build

Note: macOS automatically uses system libgit2 via Homebrew. No vcpkg needed!

Usage

Basic Commands

# Use config.toml for default options and analyze current directory
repoctx .

# Analyze specific directory with output file
repoctx src --output report.md

# Include only specific file types
repoctx . --include "*.cpp,*.h,*.py"

# Exclude certain patterns
repoctx . --exclude "test,build,node_modules"

# Only package files modified in the last 7 days
repoctx . --recent

# Show help
repoctx --help

# Show version
repoctx --version

Advanced Usage

# Analyze C++ project, excluding tests and build files
repoctx . --include "*.cpp,*.hpp,*.h" --exclude "test,build" --output cpp-analysis.md

# Analyze multiple directories
repoctx src docs

# Mix files and directories
repoctx src README.md CMakeLists.txt --output project-overview.md

# Combination of different flags
repoctx ./src --recent --exclude "README.md" --output recently-updated-files.md

Command Line Options

Option Description Example
--help, -h Show help message repoctx -h
--version, -v Show version info repoctx -v
--output, -o Output file path repoctx -o report.md
--include Include file extensions --include "*.cpp,*.h"
--exclude Exclude file patterns --exclude "test,build"
--recent Show files modified in the last 7 days repoctx . -r
--dirs-only,-d Show directory structure with other sections except for File Contents repoctx . -d
--token-count-tree Show token count tree repoctx . --token-count-tree
--token-count-tree [threshold] Show token count tree with minimum threshold repoctx . --token-count-tree 500

Config

Use config.toml to specify default arguments.
Precedence: CLI options override config.toml, which overrides built-in defaults.
Note: If you're modifying config.toml, you may need to rerun cmake --build build to ensure the updated file is copied into the build folder (depending on your setup).

Output Format

PS D:\osdProjects\RepositoryContextPackager> .\build\repoctx.exe .

# Repository Context

## File System Location

D:\osdProjects\RepositoryContextPackager

### GIT INFO

-   Commit: 4e96146d00cc70854c98e70caf5cf597553daca2
-   Branch: main
-   Author: Elshad Humbatli< [email protected] >
-   Date: Thu Sep 18 02:30:16 2025

Structure

CMakeLists.txt
CMakeSettings.json
\include
utils.hpp
LICENSE
README.md
\src
cli.cpp
cli.hpp
fs_travel.cpp
fs_travel.hpp
git_info.cpp
git_info.hpp
main.cpp
renderer.cpp
renderer.hpp
utils.cpp
filter.cpp
filter.cpp
vcpkg.json

### File:"CMakeLists.txt"

```text
cmake_minimum_required(VERSION 3.20)
project(repoctx VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
  additional data is shown about files ...

  --  At the end file data
  Total Files: 15
Total Lines: 1,247
```

Testing

This project includes comprehensive tests using Google Test (GTest) framework to ensure code reliability and maintainability.

Build Tests

# Build the project
cmake -B build
cmake --build build

# Run all tests
cd build
ctest --output-on-failure

# Or run individual test executables (Linux/macOS)
./tests/filter_test
./tests/file_stats
./tests/utils_test
./tests/git_info_test

# Windows
.\tests\filter_test.exe
.\tests\file_stats.exe
.\tests\utils_test.exe
.\tests\git_info_test.exe

Continuous Integration

This project uses GitHub Actions for automated testing on every push and pull request. The CI pipeline:

  • Builds on Ubuntu, macOS, and Windows
  • Runs 17 unit tests across all platforms
  • Ensures cross-platform compatibility

Project Structure

osdProjects/ # that is a local development directory
├── vcpkg/                          # C++ package manager
|     ├── scripts/buildsystems/vcpkg.cmake
│     └──[vcpkg installation files...]
└── RepositoryContextPackager/      # This project
    ├── include/
    │   └── utils.hpp         # Utility function declarations
    ├── src/
    │   ├── config_manager.cpp # Configuration file declarations
    │   ├── config_manager.hpp # Configuration file (config.toml) parsing
    │   ├── main.cpp          # Main entry point
    │   ├── cli.cpp           # Command-line argument parsing
    │   ├── cli.hpp           # CLI parsing declarations
    │   ├── fs_travel.cpp     # File system traversal
    │   ├── fs_travel.hpp     # File system traversal declarations
    │   ├── git_info.cpp      # Git repository information
    │   ├── git_info.hpp      # Git info declarations
    │   ├── renderer.cpp      # Output rendering
    │   ├── renderer.hpp      # Renderer declarations
    │   └── utils.cpp         # Utility functions
    |   └── filter.hpp        #Filtering declarations
    |   └── filter.cpp        # Filtering new features
    ├── CMakeLists.txt        # Build configuration
    ├── tests/
    │    ├── CMakeLists.txt
    │    ├── utils_test.cpp     # Test utils functions
    │    ├── filter_test.cpp    # Test filters
    │    ├── file_stats.cpp     # Test file statistics
    │    └── git_info_test.cpp  # Test git integration 
    │ 
    ├── vcpkg.json           # Dependencies
    └── README.md            # README file
  

Contributing

  • Fork the repository
  • Create your feature branch (git checkout -b feature/recent)
  • Commit your changes (git commit -m 'feature added')
  • Push to the branch (git push origin feature/recent)
  • Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Essentials

Built with libgit2 for Git repository access Uses vcpkg for dependency management Designed for integration with Large Language Models

About

Command-line tool that analyzes local git repositories and creates a text file containing repository content optimized for sharing with Large Language Models (LLMs).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •