From f5907cfd965f780e6bbb82c9e8ed8c0c74710a9a Mon Sep 17 00:00:00 2001 From: Aman Rusia Date: Wed, 25 Dec 2024 13:55:36 +0530 Subject: [PATCH] Workspace path not exists case --- src/wcgw/client/repo_ops/repo_context.py | 6 +++--- src/wcgw/client/tools.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/wcgw/client/repo_ops/repo_context.py b/src/wcgw/client/repo_ops/repo_context.py index 0f74594..62871e4 100644 --- a/src/wcgw/client/repo_ops/repo_context.py +++ b/src/wcgw/client/repo_ops/repo_context.py @@ -3,8 +3,8 @@ from pygit2 import GitError, Repository -from .display_tree import DirectoryTree -from .path_prob import FastPathAnalyzer +from wcgw.client.repo_ops.display_tree import DirectoryTree +from wcgw.client.repo_ops.path_prob import FastPathAnalyzer curr_folder = Path(__file__).parent vocab_file = curr_folder / "paths_model.vocab" @@ -51,7 +51,7 @@ def get_all_files_max_depth( def get_repo_context(file_or_repo_path: str, max_files: int) -> tuple[str, Path]: - file_or_repo_path_ = Path(file_or_repo_path) + file_or_repo_path_ = Path(file_or_repo_path).absolute() repo = find_ancestor_with_git(file_or_repo_path_) diff --git a/src/wcgw/client/tools.py b/src/wcgw/client/tools.py index 8f77bdb..09de68f 100644 --- a/src/wcgw/client/tools.py +++ b/src/wcgw/client/tools.py @@ -295,14 +295,18 @@ def initialize( reset_shell() repo_context = "" + if any_workspace_path: - repo_context, folder_to_start = get_repo_context(any_workspace_path, 200) + if os.path.exists(any_workspace_path): + repo_context, folder_to_start = get_repo_context(any_workspace_path, 200) - BASH_STATE.shell.sendline(f"cd {shlex.quote(str(folder_to_start))}") - BASH_STATE.shell.expect(PROMPT, timeout=0.2) - BASH_STATE.update_cwd() + BASH_STATE.shell.sendline(f"cd {shlex.quote(str(folder_to_start))}") + BASH_STATE.shell.expect(PROMPT, timeout=0.2) + BASH_STATE.update_cwd() - repo_context = f"---\n# Workspace structure\n{repo_context}\n---\n" + repo_context = f"---\n# Workspace structure\n{repo_context}\n---\n" + else: + return f"\nInfo: Workspace path {any_workspace_path} does not exist\n" initial_files_context = "" if read_files_: