Wrong path with Git Bash for Windows when using re

2019-05-30 04:44发布

问题:

I have some bash code like this:

repo="/mnt/shared/my/repo path sometimes with spaces.git"
echo "\$repo = $repo"
git remote add origin "${repo}"
git remote -v

where /mnt/shared is a mountpoint to a network drive created in the git cygwin fstab file that works fine. I can interact with it through the Git bash shell using ls and pushing and pulling repos from it no problem.

I use the above code in a loop to maintain a large set of repos, and if my repo variable is like above without any special characters at all (aside from spaces, which don't affect this situation at all), I get the following output:

$repo = /mnt/shared/my/repo path sometimes with spaces.git
origin //unc-path/to/mountpoint/my/repo path sometimes with spaces.git (fetch)
origin //unc-path/to/mountpoint/my/repo path sometimes with spaces.git (pull)

or

$repo = /mnt/shared/my/repopathnospaces.git
origin //unc-path/to/mountpoint/my/repopathnospaces.git (fetch)
origin //unc-path/to/mountpoint/my/repopathnospaces.git (pull)

BUT, if the repo variable contains any special character that would normally require escaping (again, except for spaces for some reason), then I get the output that I am actually looking for (which I want in the above case too):

$repo = /mnt/shared/my/repo path with [brackets].git
origin /mnt/shared/my/repo path with [brackets].git (fetch)
origin /mnt/shared/my/repo path with [brackets].git (pull)

or

$repo = /mnt/shared/my/repopathwith[brackets].git
origin /mnt/shared/my/repopathwith[brackets].git (fetch)
origin /mnt/shared/my/repopathwith[brackets].git (pull)   

Notice how it kept my /mnt/shared mountpoint in the path? My question is, why in the heck is it converting to the UNC path in the first case (no special characters)? And how can I get it to always maintain the mountpoint relative path here?

I'm using what I believe is the most recent version of Git Bash for Windows, and running uname gives me MINGW64_NT-6.1 if that helps at all.