Rustic Git
A Rust library for Git repository operations with a clean, type-safe API.
Overview
Rustic Git provides a simple, ergonomic interface for common Git operations. It follows a repository-centric design where you create a Repository
instance and call methods on it to perform Git operations.
Features
- ✅ Repository initialization and opening
- ✅ File status checking with detailed parsing
- ✅ File staging (add files, add all, add updates)
- ✅ Commit creation with hash return
- ✅ Type-safe error handling
- ✅ Universal
Hash
type for Git objects - ✅ Comprehensive test coverage
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Quick Start
use ;
API Documentation
Repository Lifecycle
Repository::init(path, bare) -> Result<Repository>
Initialize a new Git repository.
// Initialize a regular repository
let repo = init?;
// Initialize a bare repository
let bare_repo = init?;
Repository::open(path) -> Result<Repository>
Open an existing Git repository.
let repo = open?;
Status Operations
Repository::status() -> Result<GitStatus>
Get the current repository status.
let status = repo.status?;
// Check if repository is clean
if status.is_clean else
// Get files by status
let modified = status.modified_files;
let untracked = status.untracked_files;
// Or work with all files directly
for in &status.files
The GitStatus
struct contains:
files: Box<[(FileStatus, String)]>
- All files with their statusis_clean()
- Returns true if no changeshas_changes()
- Returns true if any changes existmodified_files()
- Get all modified filesuntracked_files()
- Get all untracked filesfiles_with_status(status)
- Get files with specific status
File Status Types
Staging Operations
Repository::add(paths) -> Result<()>
Add specific files to the staging area.
// Add single file
repo.add?;
// Add multiple files
repo.add?;
// Add with Path objects
use Path;
repo.add?;
Repository::add_all() -> Result<()>
Add all changes to the staging area (equivalent to git add .
).
repo.add_all?;
Repository::add_update() -> Result<()>
Add all tracked files that have been modified (equivalent to git add -u
).
repo.add_update?;
Commit Operations
Repository::commit(message) -> Result<Hash>
Create a commit with the given message.
let hash = repo.commit?;
println!;
println!;
Repository::commit_with_author(message, author) -> Result<Hash>
Create a commit with a custom author.
let hash = repo.commit_with_author?;
Hash Type
The Hash
type represents Git object hashes (commits, trees, blobs, etc.).
let hash = repo.commit?;
// Get full hash as string
let full_hash: &str = hash.as_str;
// Get short hash (first 7 characters)
let short_hash: &str = hash.short;
// Display formatting
println!; // Displays full hash
Error Handling
All operations return Result<T, GitError>
for proper error handling.
use ;
match repo.commit
Complete Workflow Example
use ;
use fs;
Testing
Run the test suite:
All tests create temporary repositories in /tmp/
and clean up after themselves.
Contributing
This library follows these design principles:
- Repository-centric API: Static lifecycle methods (
init
,open
) returnRepository
instances - Type safety: Strong typing with custom error types and structured return values
- Ergonomic design: Clean, intuitive API that follows Rust conventions
- Comprehensive testing: All functionality thoroughly tested
- Modular organization: Commands organized in separate modules
License
MIT License - see LICENSE file for details.
Roadmap
Future planned features:
- Commit history and log operations
- Diff operations
- Branch operations
- Remote operations (clone, push, pull)
- Merge and rebase operations
- Tag operations
- Stash operations
Version
Current version: 0.1.0 - Basic git workflow (init, status, add, commit)