mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-01-27 00:58:37 +00:00
refactor: Cleanup unwraps in create_fixture_repo function (#311)
This commit is contained in:
parent
6658b7f0aa
commit
86c4a4bdcf
@ -1,5 +1,6 @@
|
||||
use lazy_static::lazy_static;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::{env, fs, io, process};
|
||||
@ -46,34 +47,38 @@ pub fn new_tempdir() -> io::Result<tempfile::TempDir> {
|
||||
}
|
||||
|
||||
/// Create a repo from the fixture to be used in git module tests
|
||||
pub fn create_fixture_repo() -> io::Result<std::path::PathBuf> {
|
||||
let fixture_repo_dir = new_tempdir()?.path().join("fixture");
|
||||
let repo_dir = new_tempdir()?.path().join("rocket");
|
||||
let fixture = env::current_dir()?.join("tests/fixtures/rocket.bundle");
|
||||
pub fn create_fixture_repo() -> io::Result<PathBuf> {
|
||||
let fixture_repo_path = new_tempdir()?.path().join("fixture");
|
||||
let repo_path = new_tempdir()?.path().join("rocket");
|
||||
let fixture_path = env::current_dir()?.join("tests/fixtures/rocket.bundle");
|
||||
|
||||
let fixture_repo_dir = path_str(&fixture_repo_path)?;
|
||||
let repo_dir = path_str(&repo_path)?;
|
||||
let fixture = path_str(&fixture_path)?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&[
|
||||
"clone",
|
||||
"-b",
|
||||
"master",
|
||||
&fixture.to_str().unwrap(),
|
||||
fixture_repo_dir.to_str().unwrap(),
|
||||
])
|
||||
.args(&["clone", "-b", "master", fixture, fixture_repo_dir])
|
||||
.output()?;
|
||||
|
||||
git2::Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
|
||||
git2::Repository::clone(fixture_repo_dir, repo_dir).ok();
|
||||
|
||||
Command::new("git")
|
||||
.args(&["config", "--local", "user.email", "starship@example.com"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.current_dir(repo_dir)
|
||||
.output()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["config", "--local", "user.name", "starship"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.current_dir(repo_dir)
|
||||
.output()?;
|
||||
|
||||
Ok(repo_dir)
|
||||
Ok(repo_path)
|
||||
}
|
||||
|
||||
fn path_str(repo_dir: &PathBuf) -> io::Result<&str> {
|
||||
repo_dir
|
||||
.to_str()
|
||||
.ok_or_else(|| Error::from(ErrorKind::Other))
|
||||
}
|
||||
|
||||
/// Extends `std::process::Command` with methods for testing
|
||||
|
Loading…
x
Reference in New Issue
Block a user