44from jupyter_ai .tools .models import Tool , Toolkit
55from jupyterlab_git .git import Git
66
7+ from ..utils import normalize_filepath
8+
79git = Git ()
810
911
@@ -19,6 +21,7 @@ async def git_clone(path: str, url: str) -> str:
1921 Returns:
2022 str: Success or error message.
2123 """
24+ path = normalize_filepath (path )
2225 res = await git .clone (path , repo_url = url )
2326 if res ["code" ] == 0 :
2427 return f"✅ Cloned repo into { res ['path' ]} "
@@ -36,6 +39,7 @@ async def git_status(path: str) -> str:
3639 Returns:
3740 str: A JSON-formatted string of status or an error message.
3841 """
42+ path = normalize_filepath (path )
3943 res = await git .status (path )
4044 if res ["code" ] == 0 :
4145 return f"📋 Status:\n { json .dumps (res , indent = 2 )} "
@@ -54,6 +58,7 @@ async def git_log(path: str, history_count: int = 10) -> str:
5458 Returns:
5559 str: A JSON-formatted commit log or error message.
5660 """
61+ path = normalize_filepath (path )
5762 res = await git .log (path , history_count = history_count )
5863 if res ["code" ] == 0 :
5964 return f"🕓 Recent commits:\n { json .dumps (res , indent = 2 )} "
@@ -71,6 +76,7 @@ async def git_pull(path: str) -> str:
7176 Returns:
7277 str: Success or error message.
7378 """
79+ path = normalize_filepath (path )
7480 res = await git .pull (path )
7581 return (
7682 "✅ Pulled latest changes."
@@ -91,6 +97,7 @@ async def git_push(path: str, branch: str) -> str:
9197 Returns:
9298 str: Success or error message.
9399 """
100+ path = normalize_filepath (path )
94101 res = await git .push (remote = "origin" , branch = branch , path = path )
95102 return (
96103 "✅ Pushed changes."
@@ -111,6 +118,7 @@ async def git_commit(path: str, message: str) -> str:
111118 Returns:
112119 str: Success or error message.
113120 """
121+ path = normalize_filepath (path )
114122 res = await git .commit (commit_msg = message , amend = False , path = path )
115123 return (
116124 "✅ Commit successful."
@@ -132,6 +140,7 @@ async def git_add(path: str, add_all: bool = True, filename: str = "") -> str:
132140 Returns:
133141 str: Success or error message.
134142 """
143+ path = normalize_filepath (path )
135144 if add_all :
136145 res = await git .add_all (path )
137146 elif filename :
@@ -158,6 +167,7 @@ async def git_get_repo_root(path: str) -> str:
158167 Returns:
159168 str: The path to the Git repository root or an error message.
160169 """
170+ path = normalize_filepath (path )
161171 dir_path = os .path .dirname (path )
162172 res = await git .show_top_level (dir_path )
163173 if res ["code" ] == 0 and res .get ("path" ):
0 commit comments