-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use Git CLI for cloning repositories by default
- Loading branch information
Showing
8 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
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,15 @@ | ||
use serde::Deserialize; | ||
|
||
use crate::git::strategy::Strategy; | ||
|
||
#[derive(Debug, Default, Deserialize)] | ||
pub struct StrategyConfig { | ||
#[serde(default)] | ||
pub clone: Strategy, | ||
} | ||
|
||
#[derive(Debug, Default, Deserialize)] | ||
pub struct Config { | ||
#[serde(default)] | ||
pub strategy: StrategyConfig, | ||
} |
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,15 @@ | ||
mod config; | ||
mod strategy; | ||
|
||
pub use config::Config; | ||
|
||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
|
||
pub trait CloneRepository { | ||
fn clone_repository<U, P>(&self, url: U, path: P) -> Result<()> | ||
where | ||
U: ToString, | ||
P: AsRef<Path>; | ||
} |
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,24 @@ | ||
use std::path::Path; | ||
use std::process::Command; | ||
|
||
use tracing::debug; | ||
|
||
use crate::git::CloneRepository; | ||
|
||
pub struct Cli; | ||
|
||
impl CloneRepository for Cli { | ||
fn clone_repository<U, P>(&self, url: U, path: P) -> anyhow::Result<()> | ||
where | ||
U: ToString, | ||
P: AsRef<Path>, | ||
{ | ||
debug!("Cloning the repository using CLI strategy"); | ||
|
||
let _ = Command::new("git") | ||
.args(["clone", &url.to_string(), path.as_ref().to_str().unwrap()]) | ||
.output()?; | ||
|
||
Ok(()) | ||
} | ||
} |
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,22 @@ | ||
use std::path::Path; | ||
|
||
use git2::Repository; | ||
use tracing::debug; | ||
|
||
use crate::git::CloneRepository; | ||
|
||
pub struct Git2; | ||
|
||
impl CloneRepository for Git2 { | ||
fn clone_repository<U, P>(&self, url: U, path: P) -> anyhow::Result<()> | ||
where | ||
U: ToString, | ||
P: AsRef<Path>, | ||
{ | ||
debug!("Cloning the repository using Git2 strategy"); | ||
|
||
let _ = Repository::clone(&url.to_string(), path)?; | ||
|
||
Ok(()) | ||
} | ||
} |
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,30 @@ | ||
mod cli; | ||
mod git2; | ||
|
||
pub use {self::git2::Git2, cli::Cli}; | ||
|
||
use std::path::Path; | ||
|
||
use serde::Deserialize; | ||
|
||
use crate::git::CloneRepository; | ||
|
||
#[derive(Debug, Default, Deserialize)] | ||
pub enum Strategy { | ||
#[default] | ||
Cli, | ||
Git2, | ||
} | ||
|
||
impl CloneRepository for Strategy { | ||
fn clone_repository<U, P>(&self, url: U, path: P) -> anyhow::Result<()> | ||
where | ||
U: ToString, | ||
P: AsRef<Path>, | ||
{ | ||
match self { | ||
Self::Cli => Cli.clone_repository(url, path), | ||
Self::Git2 => Git2.clone_repository(url, path), | ||
} | ||
} | ||
} |
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,6 +1,7 @@ | ||
mod cmd; | ||
mod config; | ||
mod console; | ||
mod git; | ||
mod path; | ||
mod profile; | ||
mod root; | ||
|