Refactor WorkspaceManager.sanitize_repo to stash changes and raise errors on failure, add unit tests
This commit is contained in:
+15
-1
@@ -67,6 +67,19 @@ class WorkspaceManager:
|
||||
check=True, capture_output=True,
|
||||
)
|
||||
self._configure_repo_user(repo_path)
|
||||
|
||||
# Check for any uncommitted changes or untracked files
|
||||
status_res = subprocess.run(
|
||||
["git", "-C", str(repo_path), "status", "--porcelain"],
|
||||
check=True, capture_output=True, text=True
|
||||
)
|
||||
if status_res.stdout.strip():
|
||||
logger.info(f"Uncommitted changes detected in {repo_path}. Stashing before sanitization.")
|
||||
subprocess.run(
|
||||
["git", "-C", str(repo_path), "stash", "push", "-u", "-m", "Auto-backup before agent sanitization"],
|
||||
check=True, capture_output=True
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
["git", "-C", str(repo_path), "reset", "--hard", "HEAD"],
|
||||
check=True, capture_output=True,
|
||||
@@ -96,7 +109,8 @@ class WorkspaceManager:
|
||||
check=True, capture_output=True,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error during sanitization: {e}")
|
||||
logger.error(f"Error during sanitization: {e}", exc_info=True)
|
||||
raise RuntimeError(f"Failed to sanitize repository {repo_full_name} at {repo_path}: {e}") from e
|
||||
|
||||
def clone_repo(self, repo_full_name: str, clone_url: str | None = None) -> Path:
|
||||
repo_path: Path = self.get_repo_path(repo_full_name)
|
||||
|
||||
Reference in New Issue
Block a user