Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df617fd

Browse files
committed
[clone] Finish round-trip testing
1 parent aea52fe commit df617fd

6 files changed

Lines changed: 76 additions & 47 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
9696
* [x] file, git, and SSH
9797
* [x] paths (OS paths, without need for UTF-8)
9898
* [x] username expansion for ssh and git urls
99-
* [ ] convert URL to string
99+
* [x] convert URL to string
100100
* [ ] API documentation with examples
101101

102102
### git-protocol

etc/check-package-size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ echo "in root: gitoxide CLI"
1818
indent cargo diet -n --package-size-limit 25KB
1919
(enter git-features && indent cargo diet -n --package-size-limit 8KB)
2020
(enter git-ref && indent cargo diet -n --package-size-limit 4KB)
21-
(enter git-url && indent cargo diet -n --package-size-limit 5KB)
21+
(enter git-url && indent cargo diet -n --package-size-limit 6KB)
2222
(enter git-object && indent cargo diet -n --package-size-limit 15KB)
2323
(enter git-odb && indent cargo diet -n --package-size-limit 50KB)
2424
(enter git-protocol && indent cargo diet -n --package-size-limit 5KB)

git-url/tests/parse/file.rs

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,100 @@
1-
use crate::parse::{assert_url, url};
1+
use crate::parse::{assert_url_and, assert_url_roundtrip, url};
22
use git_url::Protocol;
33

44
#[test]
55
fn file_path_with_protocol() -> crate::Result {
6-
assert_url(
6+
assert_url_roundtrip(
77
"file:///path/to/git",
88
url(Protocol::File, None, None, None, b"/path/to/git"),
99
)
1010
}
1111

1212
#[test]
1313
fn file_path_without_protocol() -> crate::Result {
14-
assert_url("/path/to/git", url(Protocol::File, None, None, None, b"/path/to/git"))
14+
let url = assert_url_and("/path/to/git", url(Protocol::File, None, None, None, b"/path/to/git"))?.to_string();
15+
assert_eq!(url, "file:///path/to/git");
16+
Ok(())
1517
}
1618

1719
#[test]
1820
fn no_username_expansion_for_file_paths_without_protocol() -> crate::Result {
19-
assert_url("~/path/to/git", url(Protocol::File, None, None, None, b"~/path/to/git"))
21+
let url = assert_url_and("~/path/to/git", url(Protocol::File, None, None, None, b"~/path/to/git"))?.to_string();
22+
assert_eq!(url, "file://~/path/to/git");
23+
Ok(())
2024
}
2125
#[test]
2226
fn no_username_expansion_for_file_paths_with_protocol() -> crate::Result {
23-
assert_url(
27+
assert_url_roundtrip(
2428
"file://~username/path/to/git",
2529
url(Protocol::File, None, None, None, b"~username/path/to/git"),
2630
)
2731
}
2832

2933
#[test]
3034
fn non_utf8_file_path_without_protocol() -> crate::Result {
35+
let parsed = git_url::parse(b"/path/to\xff/git")?;
36+
assert_eq!(parsed, url(Protocol::File, None, None, None, b"/path/to\xff/git",));
3137
assert_eq!(
32-
git_url::parse(b"/path/to\xff/git")?,
33-
url(Protocol::File, None, None, None, b"/path/to\xff/git",)
38+
parsed.to_string(),
39+
"file:///path/to�/git",
40+
"non-unicode is made unicode safe"
3441
);
3542
Ok(())
3643
}
3744

3845
#[test]
3946
fn relative_file_path_without_protocol() -> crate::Result {
40-
assert_url(
47+
let parsed = assert_url_and(
4148
"../../path/to/git",
4249
url(Protocol::File, None, None, None, b"../../path/to/git"),
43-
)?;
44-
assert_url("path/to/git", url(Protocol::File, None, None, None, b"path/to/git"))
50+
)?
51+
.to_string();
52+
assert_eq!(parsed, "file://../../path/to/git");
53+
let url = assert_url_and("path/to/git", url(Protocol::File, None, None, None, b"path/to/git"))?.to_string();
54+
assert_eq!(url, "file://path/to/git");
55+
Ok(())
4556
}
4657

4758
#[test]
4859
fn interior_relative_file_path_without_protocol() -> crate::Result {
49-
assert_url(
60+
let url = assert_url_and(
5061
"/abs/path/../../path/to/git",
5162
url(Protocol::File, None, None, None, b"/abs/path/../../path/to/git"),
52-
)
63+
)?
64+
.to_string();
65+
assert_eq!(url, "file:///abs/path/../../path/to/git");
66+
Ok(())
5367
}
5468

5569
mod windows {
56-
use crate::parse::{assert_url, url};
70+
use crate::parse::{assert_url_and, assert_url_roundtrip, url};
5771
use git_url::Protocol;
5872

5973
#[test]
6074
fn file_path_without_protocol() -> crate::Result {
61-
assert_url(
75+
let url = assert_url_and(
6276
"x:/path/to/git",
6377
url(Protocol::File, None, None, None, b"x:/path/to/git"),
64-
)
78+
)?
79+
.to_string();
80+
assert_eq!(url, "file://x:/path/to/git");
81+
Ok(())
6582
}
6683

6784
#[test]
6885
fn file_path_with_backslashes_without_protocol() -> crate::Result {
69-
assert_url(
86+
let url = assert_url_and(
7087
"x:\\path\\to\\git",
7188
url(Protocol::File, None, None, None, b"x:\\path\\to\\git"),
72-
)
89+
)?
90+
.to_string();
91+
assert_eq!(url, "file://x:\\path\\to\\git");
92+
Ok(())
7393
}
7494

7595
#[test]
7696
fn file_path_with_protocol() -> crate::Result {
77-
assert_url(
97+
assert_url_roundtrip(
7898
"file://x:/path/to/git",
7999
url(Protocol::File, None, None, None, b"x:/path/to/git"),
80100
)

git-url/tests/parse/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ fn assert_url_and(url: &str, expected: git_url::Url) -> Result<git_url::Url, cra
55
Ok(expected)
66
}
77

8-
fn assert_url(url: &str, expected: git_url::Url) -> crate::Result {
9-
assert_url_and(url, expected).map(|_| ())
10-
}
11-
128
fn assert_url_roundtrip(url: &str, expected: git_url::Url) -> crate::Result {
13-
assert_eq!(assert_url_and(url, expected).map(|s| s.to_string())?, url);
9+
assert_eq!(assert_url_and(url, expected)?.to_string(), url);
1410
Ok(())
1511
}
1612

@@ -38,7 +34,7 @@ mod file;
3834
mod invalid;
3935
mod ssh;
4036
mod http {
41-
use crate::parse::{assert_url, assert_url_roundtrip, url};
37+
use crate::parse::{assert_url_roundtrip, url};
4238
use git_url::Protocol;
4339

4440
#[test]
@@ -50,19 +46,19 @@ mod http {
5046
}
5147
#[test]
5248
fn secure() -> crate::Result {
53-
assert_url(
49+
assert_url_roundtrip(
5450
"https://github.com/byron/gitoxide",
5551
url(Protocol::Https, None, "github.com", None, b"/byron/gitoxide"),
5652
)
5753
}
5854
}
5955
mod git {
60-
use crate::parse::{assert_url, url};
56+
use crate::parse::{assert_url_roundtrip, url};
6157
use git_url::Protocol;
6258

6359
#[test]
6460
fn username_expansion_with_username() -> crate::Result {
65-
assert_url(
61+
assert_url_roundtrip(
6662
"git://example.com/~byron/hello",
6763
url(Protocol::Git, None, "example.com", None, b"/~byron/hello"),
6864
)

git-url/tests/parse/ssh.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,91 @@
1-
use crate::parse::{assert_url, url};
1+
use crate::parse::{assert_url_and, assert_url_roundtrip, url};
22
use git_url::Protocol;
33

44
#[test]
55
fn without_user_and_without_port() -> crate::Result {
6-
assert_url(
6+
assert_url_roundtrip(
77
"ssh://host.xz/path/to/repo.git/",
88
url(Protocol::Ssh, None, "host.xz", None, b"/path/to/repo.git/"),
99
)
1010
}
1111

1212
#[test]
1313
fn without_user_and_with_port() -> crate::Result {
14-
assert_url("ssh://host.xz:21/", url(Protocol::Ssh, None, "host.xz", 21, b"/"))
14+
assert_url_roundtrip("ssh://host.xz:21/", url(Protocol::Ssh, None, "host.xz", 21, b"/"))
1515
}
1616

1717
#[test]
1818
fn host_is_ipv4() -> crate::Result {
19-
assert_url(
19+
assert_url_roundtrip(
2020
"ssh://127.69.0.1/hello",
2121
url(Protocol::Ssh, None, "127.69.0.1", None, b"/hello"),
2222
)
2323
}
2424

2525
#[test]
2626
fn username_expansion_with_username() -> crate::Result {
27-
assert_url(
27+
assert_url_roundtrip(
2828
"ssh://example.com/~byron/hello/git",
2929
url(Protocol::Ssh, None, "example.com", None, b"/~byron/hello/git"),
3030
)
3131
}
3232

3333
#[test]
3434
fn username_expansion_without_username() -> crate::Result {
35-
assert_url(
35+
assert_url_roundtrip(
3636
"ssh://example.com/~/hello/git",
3737
url(Protocol::Ssh, None, "example.com", None, b"/~/hello/git"),
3838
)
3939
}
4040

4141
#[test]
4242
fn with_user_and_without_port() -> crate::Result {
43-
assert_url(
43+
assert_url_roundtrip(
4444
"ssh://[email protected]/.git",
4545
url(Protocol::Ssh, "user", "host.xz", None, b"/.git"),
4646
)
4747
}
4848

4949
#[test]
5050
fn scp_like_without_user() -> crate::Result {
51-
assert_url(
51+
let url = assert_url_and(
5252
"host.xz:path/to/git",
5353
url(Protocol::Ssh, None, "host.xz", None, b"/path/to/git"),
54-
)
54+
)?
55+
.to_string();
56+
assert_eq!(url, "ssh://host.xz/path/to/git");
57+
Ok(())
5558
}
5659

5760
#[test]
5861
fn scp_like_without_user_and_username_expansion_without_username() -> crate::Result {
59-
assert_url(
62+
let url = assert_url_and(
6063
"host.xz:~/to/git",
6164
url(Protocol::Ssh, None, "host.xz", None, b"/~/to/git"),
62-
)
65+
)?
66+
.to_string();
67+
assert_eq!(url, "ssh://host.xz/~/to/git");
68+
Ok(())
6369
}
6470

6571
#[test]
6672
fn scp_like_without_user_and_username_expansion_with_username() -> crate::Result {
67-
assert_url(
73+
let url = assert_url_and(
6874
"host.xz:~byron/to/git",
6975
url(Protocol::Ssh, None, "host.xz", None, b"/~byron/to/git"),
70-
)
76+
)?
77+
.to_string();
78+
assert_eq!(url, "ssh://host.xz/~byron/to/git");
79+
Ok(())
7180
}
7281

7382
#[test]
7483
fn scp_like_with_user_and_relative_path_turns_into_absolute_path() -> crate::Result {
75-
assert_url(
84+
let url = assert_url_and(
7685
"[email protected]:./relative",
7786
url(Protocol::Ssh, "user", "host.xz", None, b"/relative"),
78-
)
87+
)?
88+
.to_string();
89+
assert_eq!(url, "ssh://[email protected]/relative");
90+
Ok(())
7991
}

tasks.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
* [x] git
3636
* [x] http(s)
3737
* **git-protocol**
38-
* [ ] delegate to support clone
39-
* [ ] assure there is a way to do fetches with have/want negotiation
40-
* [ ] progress
4138
* [ ] support for authentication providers
4239
* [ ] know why it failed by extracting PermissionErrors from io errors
4340
* [ ] implement authentication provider using git-helpers
41+
* [ ] git-url round tripping
42+
* [ ] delegate to support clone
43+
* [ ] assure there is a way to do fetches with have/want negotiation
44+
* [ ] progress
4445
* **git-ref** _(minimal)_
4546
* [ ] a way to know if a ref needs to be parsed (like `ref/name^{}`)
4647
* **gixp-pack-receive**

0 commit comments

Comments
 (0)