Skip to content

Commit

Permalink
codegen: Tweak git_ls_files
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 10, 2023
1 parent bede902 commit cff0752
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tools/codegen/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ pub fn write_raw(function_name: &str, path: &Path, contents: impl AsRef<[u8]>) -
}

pub fn git_ls_files(dir: &Path, filters: &[&str]) -> Result<Vec<(String, PathBuf)>> {
let output = Command::new("git")
.arg("ls-files")
.args(filters)
.current_dir(dir)
.output()
.with_context(|| format!("failed to run `git ls-files {filters:?}`"))?;
let mut cmd = Command::new("git");
cmd.arg("ls-files").args(filters).current_dir(dir);
let output = cmd.output().with_context(|| format!("could not execute process `{cmd:?}`"))?;
if !output.status.success() {
bail!("failed to run `git ls-files {filters:?}`");
bail!(
"process didn't exit successfully: `{cmd:?}`:\n\nSTDOUT:\n{0}\n{1}\n{0}\n\nSTDERR:\n{0}\n{2}\n{0}\n",
"-".repeat(60),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
}
Ok(str::from_utf8(&output.stdout)?
.lines()
Expand Down

0 comments on commit cff0752

Please sign in to comment.