Closed s2tephen closed 7 years ago
Fair point! Was focusing on speed and assumed it's always present. ✌️
@s2tephen Weird, .replace(/.git$/, '')
doesn't actually remove .git
for me. Works with .replace(/\.git/, '')
Do you know of any issues not checking if it's end of line?
Oh, looks like I forgot to escape the period in .git
, but that shouldn't make a difference in removing the .git
extension — I'm not sure why the end of line selector isn't working for you.
Not including $
could potentially be a problem if the remote URL contains www.git
, e.g. https://www.github.com/user/repo
. GitHub doesn't include www.
by default but if the remote is added manually, it's accepted. This also doesn't consider other git repository platforms/private repos, which could include .git
anywhere in the URL. The $
is essential for isolating file extensions only.
If you can share which remote URLs the regex was breaking on, I can take a look and debug it.
See if #8 fixes the problem.
Edits as discussed in #2. Sometimes the remote URL doesn't actually contain ".git" so this approach uses regex to only remove the substring if it exists.