Commit 45e6fa0e authored by Ben Boeckel's avatar Ben Boeckel

prepare: accept any IntoIterator for checking out paths

parent cf48eb7d
Pipeline #68687 passed with stage
......@@ -19,6 +19,7 @@ use std::ffi::OsStr;
use std::fmt::{self, Debug};
use std::fs::{self, File};
use std::io::{Read, Write};
use std::iter;
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
......@@ -186,14 +187,15 @@ trait WorkareaGitContext {
}
/// Checkout a set of paths into a workarea.
fn checkout<P>(ctx: &WorkareaGitContext, paths: &[P]) -> Result<()>
where P: AsRef<OsStr>,
fn checkout<I, P>(ctx: &WorkareaGitContext, paths: I) -> Result<()>
where I: IntoIterator<Item = P>,
P: AsRef<OsStr>,
{
// Checkout .gitmodules so that submodules work.
let ls_files = ctx.cmd()
.arg("ls-files")
.arg("--")
.args(paths)
.args(paths.into_iter())
.output()
.chain_err(|| "failed to construct ls-files command")?;
if !ls_files.status.success() {
......@@ -323,7 +325,7 @@ impl PreparingGitWorkArea {
// Explicitly do not check the return code; it is a failure.
// Checkout .gitmodules so that submodules work.
checkout(self, &[".gitmodules"])
checkout(self, iter::once(".gitmodules"))
}
/// Run a git command in the workarea.
......@@ -620,8 +622,9 @@ impl GitWorkArea {
/// and fixes up Git's knowledge that they are there.
///
/// All paths supported by Git's globbing and searching mechanisms are supported.
pub fn checkout<P>(&self, paths: &[P]) -> Result<()>
where P: AsRef<OsStr>,
pub fn checkout<I, P>(&self, paths: I) -> Result<()>
where I: IntoIterator<Item = P>,
P: AsRef<OsStr>,
{
checkout(self, paths)
}
......
......@@ -14,6 +14,7 @@ use {CommitId, Conflict, GitContext, GitWorkArea, MergeResult, MergeStatus};
use std::env;
use std::fs;
use std::iter;
use std::path::Path;
use std::process::{Command, Stdio};
......@@ -711,15 +712,15 @@ fn test_work_area_checkout() {
assert!(workarea.submodule_config().is_empty());
assert!(!workarea.__work_tree().join("rustfmt.toml").exists());
workarea.checkout(&["rustfmt.toml"]).unwrap();
workarea.checkout(iter::once("rustfmt.toml")).unwrap();
assert!(workarea.__work_tree().join("rustfmt.toml").exists());
assert!(!workarea.__work_tree().join("Cargo.toml").exists());
workarea.checkout(&["*.toml"]).unwrap();
workarea.checkout(iter::once("*.toml")).unwrap();
assert!(workarea.__work_tree().join("Cargo.toml").exists());
assert!(!workarea.__work_tree().join("src").exists());
workarea.checkout(&["src/"]).unwrap();
workarea.checkout(iter::once("src/")).unwrap();
assert!(workarea.__work_tree().join("src").exists());
assert!(workarea.__work_tree().join("src/lib.rs").exists());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment