crate::ix!();
#[async_trait]
impl<P,H> EnsureGitClean for Workspace<P,H>
where
for<'async_trait> P: From<PathBuf> + AsRef<Path> + Clone + Send + Sync + 'async_trait,
H: CrateHandleInterface<P> + Send + Sync,
{
type Error = GitError;
async fn ensure_git_clean(&self) -> Result<(), Self::Error> {
let output = Command::new("git")
.args(["status", "--porcelain"])
.current_dir(self.as_ref()) .output()
.await
.map_err(|e|
GitError::IoError {
io: Arc::new(e),
context: format!("could not run git status --porcelain in current directory: {:?}", self.as_ref()),
}
)?;
if !output.status.success() {
return Err(GitError::FailedToRunGitStatusMakeSureGitIsInstalled);
}
let stdout_str = String::from_utf8_lossy(&output.stdout);
if !stdout_str.trim().is_empty() {
return Err(GitError::WorkingDirectoryIsNotCleanAborting);
}
Ok(())
}
}