Skip to content

Commit

Permalink
chore(core): make git2 optional
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoIeni committed Apr 28, 2023
1 parent c8289ac commit 5fdf39a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions git-cliff-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ keywords = ["changelog", "generator", "conventional", "commit"]
edition = "2021"
rust-version = "1.64.0"

[features]
default = ["repo"]
repo = ["dep:git2"]

[dependencies]
glob.workspace = true
regex.workspace = true
Expand All @@ -26,6 +30,7 @@ lazy-regex = "2.5.0"
[dependencies.git2]
version = "0.17.1"
default-features = false
optional = true

[dependencies.config]
version = "0.13.3"
Expand Down
3 changes: 3 additions & 0 deletions git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::error::{
Error as AppError,
Result,
};
#[cfg(feature = "repo")]
use git2::{
Commit as GitCommit,
Signature as CommitSignature,
Expand Down Expand Up @@ -84,6 +85,7 @@ pub struct Signature {
pub timestamp: i64,
}

#[cfg(feature = "repo")]
impl<'a> From<CommitSignature<'a>> for Signature {
fn from(signature: CommitSignature<'a>) -> Self {
Self {
Expand Down Expand Up @@ -142,6 +144,7 @@ impl<'a> From<String> for Commit<'a> {
}
}

#[cfg(feature = "repo")]
impl<'a> From<&GitCommit<'a>> for Commit<'a> {
fn from(commit: &GitCommit<'a>) -> Self {
Commit {
Expand Down
1 change: 1 addition & 0 deletions git-cliff-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum Error {
#[error("UTF-8 error: `{0}`")]
Utf8Error(#[from] std::str::Utf8Error),
/// Error variant that represents errors coming out of libgit2.
#[cfg(feature = "repo")]
#[error("Git error: `{0}`")]
GitError(#[from] git2::Error),
/// Error that may occur while parsing the config file.
Expand Down
1 change: 1 addition & 0 deletions git-cliff-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod embed;
pub mod error;
/// Common release type.
pub mod release;
#[cfg(feature = "repo")]
/// Git repository.
pub mod repo;
/// Template engine.
Expand Down

0 comments on commit 5fdf39a

Please sign in to comment.