-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support scp-style shorthand urls with users other than git@ (#346)
* support scp-style shorthand urls with users other than git@ * lfs: support scp-style urls with username other than git * do not add .git to the path * add .git/info/lfs suffix to the lfs api url * fix regex
- Loading branch information
Showing
5 changed files
with
91 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import re | ||
|
||
# from https://github.com/pypa/pip/blob/303fed36c1771de4063063a866776a9103972317/src/pip/_internal/vcs/git.py#L40 | ||
# SCP (Secure copy protocol) shorthand. e.g. '[email protected]:foo/bar.git' | ||
SCP_REGEX = re.compile( | ||
r"""^ | ||
# Optional user, e.g. 'git@' | ||
(\w+@)? | ||
# Server, e.g. 'github.com'. | ||
([^/:]+): | ||
# The server-side path. e.g. 'user/project.git'. Must start with an | ||
# alphanumeric character so as not to be confusable with a Windows paths | ||
# like 'C:/foo/bar' or 'C:\foo\bar'. | ||
(\w[^:]*) | ||
$""", | ||
re.VERBOSE, | ||
) | ||
|
||
|
||
def is_scp_style_url(url: str) -> bool: | ||
return bool(SCP_REGEX.match(url)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,8 @@ def test_pygit_stash_apply_conflicts( | |
"url", | ||
[ | ||
"[email protected]:iterative/scmrepo.git", | ||
"github.com:iterative/scmrepo.git", | ||
"[email protected]:iterative/scmrepo.git", | ||
"ssh://[email protected]:12345/repository.git", | ||
], | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from scmrepo.urls import is_scp_style_url | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url", | ||
[ | ||
"[email protected]:iterative/scmrepo.git", | ||
"github.com:iterative/scmrepo.git", | ||
"[email protected]:iterative/scmrepo.git", | ||
], | ||
) | ||
def test_scp_url(url: str): | ||
assert is_scp_style_url(url) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url", | ||
[ | ||
r"C:\foo\bar", | ||
"C:/foo/bar", | ||
"/home/user/iterative/scmrepo/git", | ||
"~/iterative/scmrepo/git", | ||
"ssh://[email protected]:12345/repository.git", | ||
"https://user:[email protected]/iterative/scmrepo.git", | ||
"https://github.com/iterative/scmrepo.git", | ||
], | ||
) | ||
def test_scp_url_invalid(url: str): | ||
assert not is_scp_style_url(url) |