Re-encode cwd if path does not exist
Fixes the case where a folder name is cloned with url-encoded spaces.
Closes #1211
If I have a folder with the literal name:
repo%20with%20spaces%20in%20its%20name
jupyterlab-git does not recognize that any git repository exists in this folder (it shows the "You are not currently in a Git repository" page).
This folder is encoded into the Jupyter URL as:
http://localhost:8888/lab/tree/repo%2520with%2520spaces%2520in%2520its%2520name
I believe the problem is that this URL is somehow getting decoded twice (or more) by the time it reaches the git.py file.
The desired value after exactly 1 decode:
repo%20with%20spaces%20in%20its%20name
The actual value (2 or more decodes happening):
repo with spaces in its name
Since the folder /repo with spaces in its name does not exist, jupyterlab-git does not recognize any git repository exists.
I'm unable to identify where/how exactly the URL is getting decoded twice, to fix the root cause. So for this PR I suggest checking if the path exists:
/repo with spaces in its name
And if this path does not exist, try again but with the spaces encoded:
/repo%20with%20spaces%20in%20its%20name
This fix will correctly identify that there is a git repository inside a folder literally named: /repo%20with%20spaces%20in%20its%20name.
Hope that clarifies the problem and the fix.
Thanks for the additional explanation @ardislu
So it means that with this PR if the repository is named repo with spaces in its name it will actually be cloned within a folder named repo%20with%20spaces%20in%20its%20name. Is that correct?
And if you use the git clone command in the terminal, what is happening? Is the folder name with space escaped or not?
So it means that with this PR if the repository is named
repo with spaces in its nameit will actually be cloned within a folder namedrepo%20with%20spaces%20in%20its%20name. Is that correct?
Correct.
And if you use the
git clonecommand in the terminal, what is happening? Is the folder name with space escaped or not?
git clone also clones a folder literally named repo%20with%20spaces%20in%20its%20name.
Full end to end example:
- Here's a repo named
repo with spaces in its namein Azure DevOps (GitHub does not allow spaces in repo names):

- Azure DevOps provides the following URL to clone this repo:
https://[email protected]/ardislu/ardis.lu/_git/repo%20with%20spaces%20in%20its%20name
- Calling:
git clone https://[email protected]/ardislu/ardis.lu/_git/repo%20with%20spaces%20in%20its%20name
Gives me a folder literally named repo%20with%20spaces%20in%20its%20name. Using the Jupyter UI to clone also gives the same result.
Thanks a lot for the reply.
My fear with the current fix is that it may escape unwanted space. For example if your repository is located at /home/me/a sub folder with spaces/my%20repo, you will escape the spaces in the subfolder. So a safer fix seems to require finding why repo%2520with%2520spaces%2520in%2520its%2520name ends up being decoded twice.