Expand description
§sublime_git_tools
A high-level Rust interface to Git operations with robust error handling, built on libgit2.
§Overview
sublime_git_tools provides a user-friendly API for working with Git repositories. It wraps the
powerful but complex libgit2 library to offer a more ergonomic interface for common Git operations.
This crate is designed for Rust applications that need to:
- Create, clone, or manipulate Git repositories
- Manage branches, commits, and tags
- Track file changes between commits or branches
- Push/pull with remote repositories
- Get detailed commit histories
- Detect changes in specific parts of a repository
§Main Features
§Repository Management
use sublime_git_tools::Repo;
// Create a new repository
let repo = Repo::create("/path/to/new/repo")?;
// Open an existing repository
let repo = Repo::open("./my-project")?;
// Clone a remote repository
let repo = Repo::clone("https://github.com/example/repo.git", "./cloned-repo")?;§Branch and Commit Operations
use sublime_git_tools::Repo;
// Create a new branch
repo.create_branch("feature/new-feature")?;
// Checkout a branch
repo.checkout("feature/new-feature")?;
// Add files and commit
repo.add("src/main.rs")?;
let commit_id = repo.commit("feat: update main.rs")?;
// Or add all changes and commit in one step
let commit_id = repo.commit_changes("feat: implement new feature")?;§File Change Detection
use sublime_git_tools::Repo;
// Get all changed files since a tag or commit
let changed_files = repo.get_all_files_changed_since_sha("HEAD~1")?;
// Get all changed files with their status (Added, Modified, Deleted)
let changed_files_with_status = repo
.get_all_files_changed_since_sha_with_status("HEAD~1")?;
// Get changes in specific packages since a branch
let packages = vec!["packages/pkg1".to_string(), "packages/pkg2".to_string()];
let package_changes = repo
.get_all_files_changed_since_branch(&packages, "main")?;§Commit History
use sublime_git_tools::Repo;
// Get all commits since a specific tag
let commits = repo.get_commits_since(
Some("HEAD~1".to_string()),
&None
)?;
// Get commits affecting a specific file
let file_commits = repo.get_commits_since(
None,
&Some("src/main.rs".to_string())
)?;Structs§
- GitChanged
File - Represents a changed file in the Git repository with staging information
- GitDiff
Stats - Represents diff statistics for a file
- Repo
- Represents a Git repository with high-level operation methods
- Repo
Commit - Represents a commit in the Git repository
- Repo
Tags - Represents a tag in the Git repository
- System
EnvProvider - System environment provider using
std::env::var
Enums§
- GitFile
Status - Represents the status of a file in Git
- Repo
Error - Errors that can occur when working with Git repositories
Traits§
- EnvProvider
- Trait for accessing environment variables
Type Aliases§
- Result
- Result type alias for git operations.