Skip to content

Commit

Permalink
Shell out to git clone (#336)
Browse files Browse the repository at this point in the history
Fixes #305
  • Loading branch information
denisidoro committed Apr 11, 2020
1 parent 6678cda commit c6d17ca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 188 deletions.
167 changes: 0 additions & 167 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions Cargo.toml
Expand Up @@ -27,16 +27,6 @@ shellwords = "1.0.0"
anyhow = "1.0.27"
thiserror = "1.0.12"

[dependencies.git2]
version = "0.10.0"
default-features = false
features = ["https"]

[target.'cfg(target_os = "macos")'.dependencies.git2]
version = "0.10.0"
default-features = false
features = ["vendored-openssl"]

[lib]
name = "navi"
path = "src/lib.rs"
Expand Down
7 changes: 3 additions & 4 deletions src/flows/repo.rs
Expand Up @@ -4,7 +4,6 @@ use crate::git;
use crate::structures::finder::{Opts as FinderOpts, SuggestionType};
use anyhow::Context;
use anyhow::Error;
use git2::Repository;
use std::fs;
use std::io::Write;
use walkdir::WalkDir;
Expand All @@ -18,8 +17,8 @@ pub fn browse(finder: &FinderChoice) -> Result<(), Error> {
let _ = filesystem::remove_dir(&repo_path_str);
filesystem::create_dir(&repo_path_str)?;

let repo_url = "https://github.com/denisidoro/cheats";
Repository::clone(repo_url, &repo_path_str)
let (repo_url, _, _) = git::meta("denisidoro/cheats");
git::shallow_clone(repo_url.as_str(), &repo_path_str)
.with_context(|| format!("Failed to clone `{}`", repo_url))?;

let repos = fs::read_to_string(format!("{}/featured_repos.txt", &repo_path_str))
Expand Down Expand Up @@ -56,7 +55,7 @@ pub fn add(uri: String, finder: &FinderChoice) -> Result<(), Error> {

eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);

Repository::clone(actual_uri.as_str(), &tmp_path_str)
git::shallow_clone(actual_uri.as_str(), &tmp_path_str)
.with_context(|| format!("Failed to clone `{}`", actual_uri))?;

let all_files = WalkDir::new(&tmp_path_str)
Expand Down
25 changes: 18 additions & 7 deletions src/git.rs
@@ -1,8 +1,22 @@
use crate::structures::error::command::BashSpawnError;
use anyhow::{Context, Error};
use std::process::Command;

pub fn shallow_clone(uri: &str, target: &str) -> Result<(), Error> {
let cmd = format!("git clone {} {} --depth 1", uri, target);
Command::new("bash")
.arg("-c")
.arg(&cmd[..])
.spawn()
.map_err(|e| BashSpawnError::new(&cmd[..], e))?
.wait()
.context("Unable to git clone")?;
Ok(())
}

pub fn meta(uri: &str) -> (String, String, String) {
let actual_uri = if uri.contains("://") {
let actual_uri = if uri.contains("://") || uri.contains('@') {
uri.to_string()
} else if uri.contains('@') {
uri.replace(':', "/").replace("git@", "https://")
} else {
format!("https://github.com/{}", uri)
};
Expand All @@ -29,10 +43,7 @@ mod tests {
#[test]
fn test_meta_github_ssh() {
let (actual_uri, user, repo) = meta("git@github.com:denisidoro/navi.git");
assert_eq!(
actual_uri,
"https://github.com/denisidoro/navi.git".to_string()
);
assert_eq!(actual_uri, "git@github.com/denisidoro/navi.git".to_string());
assert_eq!(user, "denisidoro".to_string());
assert_eq!(repo, "navi".to_string());
}
Expand Down

0 comments on commit c6d17ca

Please sign in to comment.