Force ssh clone, support github repo
This commit is contained in:
parent
5172e2cb57
commit
d8e6a6cee9
|
@ -4,7 +4,7 @@ extern crate log;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use gclone::git::{clone, parse_url, GCLONE_PATH};
|
use gclone::git::{clone, parse_url, parse_to_url, GCLONE_PATH};
|
||||||
use gclone::{first_arg, Cache, Result};
|
use gclone::{first_arg, Cache, Result};
|
||||||
|
|
||||||
fn help() {
|
fn help() {
|
||||||
|
@ -37,6 +37,8 @@ fn main_result() -> Result<()> {
|
||||||
path.push(&owner);
|
path.push(&owner);
|
||||||
path.push(&repo);
|
path.push(&repo);
|
||||||
|
|
||||||
|
let url = parse_to_url(&server, &owner, &repo);
|
||||||
|
|
||||||
// Clone repository
|
// Clone repository
|
||||||
info!("{} {}{}", "cloning", url, "...");
|
info!("{} {}{}", "cloning", url, "...");
|
||||||
clone(&url, &path)?;
|
clone(&url, &path)?;
|
||||||
|
|
23
src/git.rs
23
src/git.rs
|
@ -38,8 +38,10 @@ macro_rules! unwrap {
|
||||||
pub fn parse_url(input: &str) -> Result<(String, String, String)> {
|
pub fn parse_url(input: &str) -> Result<(String, String, String)> {
|
||||||
if input.starts_with("http") {
|
if input.starts_with("http") {
|
||||||
parse_http_url(input)
|
parse_http_url(input)
|
||||||
} else {
|
} else if input.starts_with("ssh") {
|
||||||
parse_ssh_url(input)
|
parse_ssh_url(input)
|
||||||
|
} else {
|
||||||
|
parse_github_url(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +73,25 @@ fn parse_ssh_url(input: &str) -> Result<(String, String, String)> {
|
||||||
Ok((server, owner, repo))
|
Ok((server, owner, repo))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parses a github url in the format owner/repo.
|
||||||
|
fn parse_github_url(input: &str) -> Result<(String, String, String)> {
|
||||||
|
let split = input.split("/").collect::<Vec<_>>();
|
||||||
|
if split.len() != 2 {
|
||||||
|
return Err(Error::GitUrlParseError);
|
||||||
|
}
|
||||||
|
|
||||||
|
let server = String::from("github.com");
|
||||||
|
let owner = String::from(split[0]);
|
||||||
|
let repo = String::from(split[1]);
|
||||||
|
|
||||||
|
Ok((server, owner, repo))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts the parse result of a repo into an url.
|
||||||
|
pub fn parse_to_url(server: &str, owner: &str, repo: &str) -> String {
|
||||||
|
format!("git@{}:{}/{}", server, owner, repo)
|
||||||
|
}
|
||||||
|
|
||||||
/// Clones a git repository in the right place.
|
/// Clones a git repository in the right place.
|
||||||
///
|
///
|
||||||
/// If an error happens, it deletes the directory created.
|
/// If an error happens, it deletes the directory created.
|
||||||
|
|
Loading…
Reference in New Issue