From 4d1a5256051f09b4fa73613b96a65c6686f27bb5 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 3 Feb 2023 20:09:29 -0800 Subject: [PATCH] Re-encode cwd if path does not exist Fixes the case where a folder name is cloned with url-encoded spaces --- jupyterlab_git/git.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py index e91f9d00c..a7cbef25c 100644 --- a/jupyterlab_git/git.py +++ b/jupyterlab_git/git.py @@ -11,7 +11,7 @@ import traceback from typing import Dict, List, Optional from unittest.mock import NonCallableMock -from urllib.parse import unquote +from urllib.parse import quote, unquote import nbformat import pexpect @@ -73,6 +73,9 @@ async def call_subprocess_with_authentication( env: "Optional[Dict[str, str]]" = None, ) -> "Tuple[int, str, str]": try: + if not os.path.exists(cwd): + cwd = quote(cwd, safe=":/\\") + p = pexpect.spawn( cmdline[0], cmdline[1:], @@ -112,6 +115,9 @@ def call_subprocess( cwd: "Optional[str]" = None, env: "Optional[Dict[str, str]]" = None, ) -> "Tuple[int, str, str]": + if not os.path.exists(cwd): + cwd = quote(cwd, safe=":/\\") + process = subprocess.Popen( cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env )