-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support install directly from git repo
Fixed #3 Signed-off-by: Jiahao XU <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,351 additions
and
101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
|
||
pub mod args; | ||
pub mod bin_util; | ||
pub mod entry; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::{num::NonZeroU32, path::Path, str::FromStr, sync::atomic::AtomicBool}; | ||
|
||
use gix::{clone, create, open, progress::Discard, remote, Url}; | ||
use thiserror::Error as ThisError; | ||
use tracing::debug; | ||
|
||
#[derive(Debug, ThisError)] | ||
#[non_exhaustive] | ||
pub enum GitError { | ||
#[error("Failed to prepare for fetch: {0}")] | ||
PrepareFetchError(#[source] Box<clone::Error>), | ||
|
||
#[error("Failed to fetch: {0}")] | ||
FetchError(#[source] Box<clone::fetch::Error>), | ||
|
||
#[error("Failed to checkout: {0}")] | ||
CheckOutError(#[source] Box<clone::checkout::main_worktree::Error>), | ||
} | ||
|
||
impl From<clone::Error> for GitError { | ||
fn from(e: clone::Error) -> Self { | ||
Self::PrepareFetchError(Box::new(e)) | ||
} | ||
} | ||
|
||
impl From<clone::fetch::Error> for GitError { | ||
fn from(e: clone::fetch::Error) -> Self { | ||
Self::FetchError(Box::new(e)) | ||
} | ||
} | ||
|
||
impl From<clone::checkout::main_worktree::Error> for GitError { | ||
fn from(e: clone::checkout::main_worktree::Error) -> Self { | ||
Self::CheckOutError(Box::new(e)) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct GitUrl(Url); | ||
|
||
impl FromStr for GitUrl { | ||
type Err = gix::url::parse::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Url::try_from(s).map(Self) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Repository(gix::Repository); | ||
|
||
impl Repository { | ||
/// WARNING: This is a blocking operation, if you want to use it in | ||
/// async context then you must wrap the call in [`tokio::task::spawn_blocking`]. | ||
pub fn shallow_clone(url: GitUrl, path: &Path) -> Result<Self, GitError> { | ||
debug!("Shallow cloning {url:?} to {}", path.display()); | ||
|
||
let mut progress = Discard; | ||
|
||
Ok(Self( | ||
clone::PrepareFetch::new( | ||
url.0, | ||
path, | ||
create::Kind::WithWorktree, | ||
create::Options { | ||
destination_must_be_empty: true, | ||
..Default::default() | ||
}, | ||
open::Options::isolated(), | ||
)? | ||
.with_shallow(remote::fetch::Shallow::DepthAtRemote( | ||
NonZeroU32::new(1).unwrap(), | ||
)) | ||
.fetch_then_checkout(&mut progress, &AtomicBool::new(false))? | ||
.0 | ||
.main_worktree(&mut progress, &AtomicBool::new(false))? | ||
.0, | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
|
||
pub mod bins; | ||
pub mod drivers; | ||
pub mod errors; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.