Skip to content

Commit 1c73496

Browse files
authored
Expand git2 version range to include 0.21.x (#236)
1 parent d9599e2 commit 1c73496

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ env_logger = { version = "0.11.8", default-features = false, features = [
3838
"auto-color",
3939
], optional = true }
4040
fs4 = "0.13.1"
41-
git2 = { version = ">=0.18.0, <0.21.0" }
41+
git2 = { version = ">=0.18.0, <0.22.0", features = ["ssh", "https"] }
4242
# Upgrading home to 0.5.11 will bring MSRV to 1.81.0
4343
home = "0.5.9"
4444
log = "0.4.27"

src/git/backend/libgit2.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl GitRepository for Libgit2Repository {
8383
match result {
8484
Ok(remote) => {
8585
let url = remote.url().map(|s| s.to_string());
86-
Ok(url)
86+
Ok(url.into_option())
8787
}
8888
Err(e) if e.code() == git2::ErrorCode::NotFound => Ok(None),
8989
Err(e) => Err(e.into()),
@@ -305,3 +305,21 @@ impl From<git2::Error> for GitBackendError {
305305
}
306306
}
307307
}
308+
309+
// Starting from git2 0.21, some methods return Result<T, git2::Error> that previously used to return Option<T>.
310+
// This is a compatibility layer to be able to keep a broad git2 dependency range.
311+
trait Git2ResultCompat<T> {
312+
fn into_option(self) -> Option<T>;
313+
}
314+
315+
impl<T> Git2ResultCompat<T> for Result<T, git2::Error> {
316+
fn into_option(self) -> Option<T> {
317+
self.ok()
318+
}
319+
}
320+
321+
impl<T> Git2ResultCompat<T> for Option<T> {
322+
fn into_option(self) -> Option<T> {
323+
self
324+
}
325+
}

0 commit comments

Comments
 (0)