-
-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Git allows relative paths in e.g. git clone
, so the following all work:
dzuelke@localhost:~/Code/oss$ git clone git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-localclone'...
done.
dzuelke@localhost:~/Code/oss$ git clone ./git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-localclone'...
done.
dzuelke@localhost:~/Code/oss$ git clone ../oss/git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-localclone'...
done.
For file://
, only absolute paths are allowed, and the host portion is ignored; this is all in compliance with RFC 8089:
dzuelke@localhost:~/Code/oss$ git clone git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-rs-localclone'...
fatal: no path specified; see 'git help pull' for valid url syntax
dzuelke@localhost:~/Code/oss$ git clone file://./git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-rs-localclone'...
fatal: '/git-url-parse-rs' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
dzuelke@localhost:~/Code/oss$ git clone file://$(pwd)/git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-rs-localclone'...
remote: Enumerating objects: 436, done.
remote: Counting objects: 100% (436/436), done.
remote: Compressing objects: 100% (226/226), done.
remote: Total 436 (delta 216), reused 364 (delta 180), pack-reused 0 (from 0)
Receiving objects: 100% (436/436), 119.95 KiB | 23.99 MiB/s, done.
Resolving deltas: 100% (216/216), done.
dzuelke@localhost:~/Code/oss$ git clone file://localhost$(pwd)/git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-rs-localclone'...
remote: Enumerating objects: 436, done.
remote: Counting objects: 100% (436/436), done.
remote: Compressing objects: 100% (226/226), done.
remote: Total 436 (delta 216), reused 364 (delta 180), pack-reused 0 (from 0)
Receiving objects: 100% (436/436), 119.95 KiB | 29.99 MiB/s, done.
Resolving deltas: 100% (216/216), done.
dzuelke@localhost:~/Code/oss$ git clone file://randomhost$(pwd)/git-url-parse-rs git-url-parse-rs-localclone
Cloning into 'git-url-parse-rs-localclone'...
remote: Enumerating objects: 436, done.
remote: Counting objects: 100% (436/436), done.
remote: Compressing objects: 100% (226/226), done.
remote: Total 436 (delta 216), reused 364 (delta 180), pack-reused 0 (from 0)
Receiving objects: 100% (436/436), 119.95 KiB | 29.99 MiB/s, done.
Resolving deltas: 100% (216/216), done.
This library currently supports the following:
./local/path
(parses to./local/path
)../local/path
(parses to../local/path
)file://./local/path
(parses to./local/path
, but according to RFC 8089 should be/local/path
with a host of.
)file://../local/path
(parses to../local/path
, but according to RFC 8089 should be/local/path
with a host of..
)
But not these:
local/path
(URL parse failed: InvalidPathEmpty
)file://localhost/local/path
(URL parse failed: InvalidFilePattern
, but according to RFC 8089 should be/local/path
with a host oflocalhost
)file://anything/local/path
(URL parse failed: InvalidFilePattern
, but according to RFC 8089 should be/local/path
with a host ofanything
)
These all worked in 0.4, although it normalized file://localhost/foo/bar
to file:///foo/bar
, but file://./foo/bar
to file://./foo/bar
(and the same for ..
).
I think it would be useful to change the behavior to be compliant with RFC 8089 and with what Git supports, i.e., as follows:
relative/path
: allowed, yieldsrelative/path
;./relative/path
: allowed, yields./relative/path
;../relative/path
: allowed, yields../relative/path
;/absolute/path
: allowed, yields/absolute/path
;file://relative/path
: allowed, yields/path
(and ahost
ofSome("relative")
);file://./relative/path
: allowed, yields/relative/path
(and ahost
ofSome(".")
);file://../relative/path
: allowed, yields/relative/path
(and ahost
ofSome("..")
);file:///absolute/path
: allowed, yields/absolute/path
(and ahost
ofNone
)
This would also match the behavior of url::Url
for file://
URLs.
The obvious trouble here is that url::Url
cannot represent local-path URLs, so GitUrl::parse_to_url
would fail for the relative path cases without a file://
scheme prefix, but IMO, that's acceptable as long as GitUrl::parse()
supports it.