Commit 9a2f9299 authored by Ben Boeckel's avatar Ben Boeckel

prepare: split the checkout function

This reduces the amount of generic code in the module.
parent 0d170839
Pipeline #43722 passed with stage
......@@ -16,6 +16,7 @@ use super::error::*;
use super::git::{CommitId, GitContext};
use std::collections::hash_map::HashMap;
use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::marker::PhantomData;
......@@ -118,6 +119,11 @@ fn checkout<P>(ctx: &WorkareaGitContext, paths: &[P]) -> Result<()>
bail!(ErrorKind::Git(format!("listing paths in the index: {}",
String::from_utf8_lossy(&ls_files.stderr))));
}
checkout_files(ctx, &ls_files.stdout)
}
fn checkout_files(ctx: &WorkareaGitContext, files: &[u8]) -> Result<()> {
let mut checkout_index = try!(ctx.cmd()
.arg("checkout-index")
.arg("-f")
......@@ -131,7 +137,7 @@ fn checkout<P>(ctx: &WorkareaGitContext, paths: &[P]) -> Result<()>
try!(checkout_index.stdin
.as_mut()
.unwrap()
.write_all(&ls_files.stdout)
.write_all(files)
.chain_err(|| ErrorKind::Git("writing to checkout-index".to_string())));
let res = checkout_index.wait().unwrap();
if !res.success() {
......@@ -156,7 +162,7 @@ fn checkout<P>(ctx: &WorkareaGitContext, paths: &[P]) -> Result<()>
try!(update_index.stdin
.as_mut()
.unwrap()
.write_all(&ls_files.stdout)
.write_all(files)
.chain_err(|| ErrorKind::Git("writing to update-index".to_string())));
let res = update_index.wait().unwrap();
if !res.success() {
......
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