jupyterlab-git icon indicating copy to clipboard operation
jupyterlab-git copied to clipboard

Re-encode cwd if path does not exist

Open ardislu opened this issue 3 years ago • 6 comments

Fixes the case where a folder name is cloned with url-encoded spaces.

Closes #1211

ardislu avatar Feb 04 '23 04:02 ardislu

Binder :point_left: Launch a binder notebook on branch ardislu/jupyterlab-git/fix-spaces-in-repo-name

github-actions[bot] avatar Feb 04 '23 04:02 github-actions[bot]

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.

ardislu avatar Feb 08 '23 04:02 ardislu

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?

fcollonval avatar Feb 08 '23 10:02 fcollonval

And if you use the git clone command in the terminal, what is happening? Is the folder name with space escaped or not?

fcollonval avatar Feb 08 '23 10:02 fcollonval

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?

Correct.

And if you use the git clone command 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:

  1. Here's a repo named repo with spaces in its name in Azure DevOps (GitHub does not allow spaces in repo names):

How a repo named "repo with spaces in its name" appears in the Azure DevOps UI

  1. Azure DevOps provides the following URL to clone this repo:
https://[email protected]/ardislu/ardis.lu/_git/repo%20with%20spaces%20in%20its%20name
  1. 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.

ardislu avatar Feb 09 '23 03:02 ardislu

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.

fcollonval avatar Feb 09 '23 11:02 fcollonval