sublime_git_tools/
lib.rs

1//! # sublime_git_tools
2//!
3//! A high-level Rust interface to Git operations with robust error handling, built on libgit2.
4//!
5//! ## Overview
6//!
7//! `sublime_git_tools` provides a user-friendly API for working with Git repositories. It wraps the
8//! powerful but complex libgit2 library to offer a more ergonomic interface for common Git operations.
9//!
10//! This crate is designed for Rust applications that need to:
11//!
12//! - Create, clone, or manipulate Git repositories
13//! - Manage branches, commits, and tags
14//! - Track file changes between commits or branches
15//! - Push/pull with remote repositories
16//! - Get detailed commit histories
17//! - Detect changes in specific parts of a repository
18//!
19//! ## Main Features
20//!
21//! ### Repository Management
22//!
23//! ```rust
24//! use sublime_git_tools::Repo;
25//!
26//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
27//! // Create a new repository
28//! let repo = Repo::create("/path/to/new/repo")?;
29//!
30//! // Open an existing repository
31//! let repo = Repo::open("./my-project")?;
32//!
33//! // Clone a remote repository
34//! let repo = Repo::clone("https://github.com/example/repo.git", "./cloned-repo")?;
35//! # Ok(())
36//! # }
37//! ```
38//!
39//! ### Branch and Commit Operations
40//!
41//! ```rust
42//! use sublime_git_tools::Repo;
43//!
44//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
45//! # let repo = Repo::create("/tmp/example")?;
46//! // Create a new branch
47//! repo.create_branch("feature/new-feature")?;
48//!
49//! // Checkout a branch
50//! repo.checkout("feature/new-feature")?;
51//!
52//! // Add files and commit
53//! repo.add("src/main.rs")?;
54//! let commit_id = repo.commit("feat: update main.rs")?;
55//!
56//! // Or add all changes and commit in one step
57//! let commit_id = repo.commit_changes("feat: implement new feature")?;
58//! # Ok(())
59//! # }
60//! ```
61//!
62//! ### File Change Detection
63//!
64//! ```rust
65//! use sublime_git_tools::Repo;
66//!
67//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
68//! # let repo = Repo::create("/tmp/example")?;
69//! // Get all changed files since a tag or commit
70//! let changed_files = repo.get_all_files_changed_since_sha("HEAD~1")?;
71//!
72//! // Get all changed files with their status (Added, Modified, Deleted)
73//! let changed_files_with_status = repo
74//!     .get_all_files_changed_since_sha_with_status("HEAD~1")?;
75//!
76//! // Get changes in specific packages since a branch
77//! let packages = vec!["packages/pkg1".to_string(), "packages/pkg2".to_string()];
78//! let package_changes = repo
79//!     .get_all_files_changed_since_branch(&packages, "main")?;
80//! # Ok(())
81//! # }
82//! ```
83//!
84//! ### Commit History
85//!
86//! ```rust
87//! use sublime_git_tools::Repo;
88//!
89//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
90//! # let repo = Repo::create("/tmp/example")?;
91//! // Get all commits since a specific tag
92//! let commits = repo.get_commits_since(
93//!     Some("HEAD~1".to_string()),
94//!     &None
95//! )?;
96//!
97//! // Get commits affecting a specific file
98//! let file_commits = repo.get_commits_since(
99//!     None,
100//!     &Some("src/main.rs".to_string())
101//! )?;
102//! # Ok(())
103//! # }
104//! ```
105
106#![warn(missing_docs)]
107#![warn(rustdoc::missing_crate_level_docs)]
108#![deny(unused_must_use)]
109#![deny(clippy::unwrap_used)]
110#![deny(clippy::expect_used)]
111#![deny(clippy::todo)]
112#![deny(clippy::unimplemented)]
113#![deny(clippy::panic)]
114
115mod env;
116mod repo;
117mod types;
118
119#[cfg(test)]
120mod tests;
121
122#[cfg(test)]
123pub use env::MockEnvProvider;
124pub use env::{EnvProvider, SystemEnvProvider};
125
126pub use types::{
127    GitChangedFile, GitDiffStats, GitFileStatus, Repo, RepoCommit, RepoError, RepoTags,
128};
129
130/// Result type alias for git operations.
131///
132/// This is a convenience type alias for Results with `RepoError`.
133///
134/// # Examples
135///
136/// ```
137/// use sublime_git_tools::{Result, Repo};
138///
139/// fn open_repository(path: &str) -> Result<Repo> {
140///     Repo::open(path)
141/// }
142/// ```
143pub type Result<T> = std::result::Result<T, RepoError>;