Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
yozhgoor committed Sep 27, 2024
1 parent 91f502a commit 5949fe7
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use std::{
process::Command,
};

pub enum Project {
Temporary(tempfile::TempDir),
}
pub struct Project(tempfile::TempDir);

impl Project {
pub fn execute(cli: Cli, config: Config) -> Result<()> {
Expand All @@ -26,7 +24,7 @@ impl Project {
config.vcs.as_deref(),
)?;

let project_path = project.path();
let project_path = project.0.path();

let delete_file = project_path.join("TO_DELETE");
write(
Expand Down Expand Up @@ -244,7 +242,7 @@ impl Project {
)?;
}

Ok(Self::Temporary(tmp_dir))
Ok(Project(tmp_dir))
}

fn clean_up(
Expand Down Expand Up @@ -290,22 +288,17 @@ impl Project {
let tmp_dir = self.preserve_dir(project_name, preserved_project_dir)?;

log::info!("Project directory_preserved_at: {}", tmp_dir.display());
} else {
match self {
Self::Temporary(tempdir) => {
if worktree_branch.is_some() {
let mut command = std::process::Command::new("git");
command
.args(["worktree", "remove"])
.arg(tempdir.path())
.arg("--force");
ensure!(
command.status().context("Could not start git")?.success(),
"cannot remove working tree"
);
}
}
}
} else if worktree_branch.is_some() {
let mut command = std::process::Command::new("git");
command
.args(["worktree", "remove"])
.arg(self.0.path())
.arg("--force");

ensure!(
command.status().context("Could not start git")?.success(),
"cannot remove working tree"
);
}

kill_subprocesses(subprocesses)
Expand All @@ -316,9 +309,7 @@ impl Project {
project_name: Option<&str>,
preserved_project_dir: Option<&Path>,
) -> Result<PathBuf> {
let tmp_dir = match self {
Self::Temporary(tempdir) => tempdir.into_path(),
};
let tmp_dir = self.0.into_path();

let mut final_dir = if let Some(preserved_project_dir) = preserved_project_dir {
if !preserved_project_dir.exists() {
Expand All @@ -345,10 +336,4 @@ impl Project {

Ok(final_dir)
}

fn path(&self) -> &Path {
match self {
Self::Temporary(tempdir) => tempdir.path(),
}
}
}

0 comments on commit 5949fe7

Please sign in to comment.