From 97bf86c535cc40c1583d3cd34adb6920b0cfabd6 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 2 Jul 2014 18:26:52 -0600 Subject: [PATCH] Optionally, don't remove a repo when errors occur Signed-off-by: Zack Cerza --- teuthology/repo_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index bf5a28cbbb97d..6538f0d371cdd 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -7,7 +7,7 @@ import time log = logging.getLogger(__name__) -def enforce_repo_state(repo_url, dest_path, branch): +def enforce_repo_state(repo_url, dest_path, branch, remove_on_error=True): """ Use git to either clone or update a given repo, forcing it to switch to the specified branch. @@ -15,6 +15,7 @@ def enforce_repo_state(repo_url, dest_path, branch): :param repo_url: The full URL to the repo (not including the branch) :param dest_path: The full path to the destination directory :param branch: The branch. + :param remove: Whether or not to remove dest_dir when an error occurs :raises: BranchNotFoundError if the branch is not found; RuntimeError for other errors """ @@ -33,7 +34,8 @@ def enforce_repo_state(repo_url, dest_path, branch): reset_repo(repo_url, dest_path, branch) except BranchNotFoundError: - shutil.rmtree(dest_path, ignore_errors=True) + if remove_on_error: + shutil.rmtree(dest_path, ignore_errors=True) raise -- 2.39.5