Skip to content

Commit

Permalink
fix: remove repo path on failed install
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhermoso committed Jan 13, 2025
1 parent 1c1a0e1 commit a9bd7f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ pub fn git_clone(repo_url: &str, target_dir: &Path, revision: Option<&str>) -> R
.with_context(|| format!("Failed to clone repository from {}", repo_url))?;

let revision_str = revision.unwrap_or("main");
return git_to_revision(target_dir, "origin", revision_str);
let result = git_to_revision(target_dir, "origin", revision_str);
if let Err(e) = result {
// Cleanup! If we cannot checkout the revision, remove the directory.
fs::remove_dir_all(target_dir)
.with_context(|| format!("Failed to remove directory {}", target_dir.display()))?;
return Err(e);
}
Ok(())
}

pub fn git_update(repo_path: &Path, repo_url: &str, revision: Option<&str>) -> Result<()> {
Expand Down
13 changes: 13 additions & 0 deletions tests/cli_install_subcommand_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ revision = "invalid-revision"
"##;
write_to_file(&config_path, config_content)?;

let mut repo_path = repo_path.clone();
repo_path.push("repos");
repo_path.push("tinted-jqp");

// ---
// Act
// ---
Expand All @@ -339,11 +343,20 @@ revision = "invalid-revision"
// ------
// Assert
// ------
let path_exists = repo_path.exists();
cleanup()?;
assert!(
stderr.contains("cannot resolve invalid-revision"),
"Expected revision not found",
);

assert!(
!path_exists,
"Expected repo path {} to not exist",
repo_path.display(),

Check warning on line 356 in tests/cli_install_subcommand_tests.rs

View workflow job for this annotation

GitHub Actions / lint / fmt

Diff in /home/runner/work/tinty/tinty/tests/cli_install_subcommand_tests.rs
);



Ok(())
}

0 comments on commit a9bd7f2

Please sign in to comment.