Debian Codegraph @

src/git_config/remote.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
3
4 use lazy_staticrust-analyzer cargo lazy_static 1.4.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!;
5 use regexrust-analyzer cargo regex 1.12.3 crate/::Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#;
6
7 use craterust-analyzer cargo git-delta 0.19.2 crate/::errorsrust-analyzer cargo git-delta 0.19.2 errors/::*;
8
9 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
10 pub enum GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo# {
11 GitHubrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub#slug.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
12 GitLabrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab#slug.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
13 SourceHutrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut#slug.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
14 Codebergrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg#slug.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
15 }
16
17 impl GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo# {
18 pub fn format_commit_urlrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]format_commit_url().(&self, commit: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
19 match self {
20 Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]::GitHubrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub#slug. } => {
21 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://github.com/{slug}/commit/{commit}")
22 }
23 Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]::GitLabrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab#slug. } => {
24 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://gitlab.com/{slug}/-/commit/{commit}")
25 }
26 Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]::SourceHutrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut#slug. } => {
27 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://git.sr.ht/{slug}/commit/{commit}")
28 }
29 Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]::Codebergrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg# { slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg#slug. } => {
30 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://codeberg.org/{slug}/commit/{commit}")
31 }
32 }
33 }
34
35 #[cfg(test)]
36 pub fn for_testingrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]for_testing().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#> {
37 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::GitHubrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub# {
38 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub#slug.: "dandavison/delta".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
39 })
40 }
41 }
42
43 lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!! {
44 static ref GITHUB_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/GITHUB_REMOTE_URL#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().(
45 r"(?x)
46 ^
47 (?:https://|[^@]+@)? # Support both HTTPS and SSH URLs
48 github\.com
49 [:/] # This separator differs between SSH and HTTPS URLs
50 ([^/]+) # Capture the user/org name
51 /
52 (.+?) # Capture the repo name (lazy to avoid consuming '.git' if present)
53 (?:\.git)? # Non-capturing group to consume '.git' if present
54 $
55 "
56 )
57 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
58 static ref GITLAB_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/GITLAB_REMOTE_URL#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().(
59 r"(?x)
60 ^
61 (?:https://|git@)? # Support both HTTPS and SSH URLs, SSH URLs optionally omitting the git@
62 gitlab\.com
63 [:/] # This separator differs between SSH and HTTPS URLs
64 ([^/]+) # Capture the user/org name
65 (/.*)? # Capture group(s), if any
66 /
67 (.+?) # Capture the repo name (lazy to avoid consuming '.git' if present)
68 (?:\.git)? # Non-capturing group to consume '.git' if present
69 $
70 "
71 )
72 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
73 static ref SOURCEHUT_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/SOURCEHUT_REMOTE_URL#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().(
74 r"(?x)
75 ^
76 (?:https://|git@)? # Support both HTTPS and SSH URLs, SSH URLs optionally omitting the git@
77 git\.sr\.ht
78 [:/] # This separator differs between SSH and HTTPS URLs
79 ~([^/]+) # Capture the username
80 /
81 (.+) # Capture the repo name
82 $
83 "
84 )
85 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
86 static ref CODEBERG_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/CODEBERG_REMOTE_URL#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().(
87 r"(?x)
88 ^
89 (?:https://|git@)? # Support both HTTPS and SSH URLs, SSH URLs optionally omitting the git@
90 codeberg\.org
91 [:/] # This separator differs between SSH and HTTPS URLs
92 ([^/]+) # Capture the user/org name
93 /
94 (.+?) # Capture the repo name (lazy to avoid consuming '.git' if present)
95 (?:\.git)? # Non-capturing group to consume '.git' if present
96 $
97 "
98 )
99 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
100 }
101
102 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo# {
103 type Errrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]Err# = Errorrust-analyzer cargo anyhow 1.0.102 Error#;
104 fn from_strrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr], Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
105 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = GITHUB_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/GITHUB_REMOTE_URL..capturesrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures().(s) {
106 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]::GitHubrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub# {
107 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub#slug.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
108 "{user}/{repo}",
109 user = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().(),
110 repo = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().()
111 ),
112 })
113 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = GITLAB_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/GITLAB_REMOTE_URL..capturesrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures().(s) {
114 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]::GitLabrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab# {
115 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab#slug.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
116 "{user}{groups}/{repo}",
117 user = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().(),
118 groups = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(2).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().()).unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(),
119 repo = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(3).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().()
120 ),
121 })
122 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = SOURCEHUT_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/SOURCEHUT_REMOTE_URL..capturesrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures().(s) {
123 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]::SourceHutrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut# {
124 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut#slug.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
125 "~{user}/{repo}",
126 user = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().(),
127 repo = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().()
128 ),
129 })
130 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(caps) = CODEBERG_REMOTE_URLrust-analyzer cargo git-delta 0.19.2 git_config/remote/CODEBERG_REMOTE_URL..capturesrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures().(s) {
131 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]::Codebergrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg# {
132 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg#slug.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
133 "{user}/{repo}",
134 user = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().(),
135 repo = caps.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Match<'h>`]as_str().()
136 ),
137 })
138 } else {
139 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.102 macros/anyhow!!("Not a GitHub, GitLab, SourceHut or Codeberg repo."))
140 }
141 }
142 }
143
144 #[cfg(test)]
145 mod testsrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/ {
146 use superrust-analyzer cargo git-delta 0.19.2 git_config/remote/::*;
147
148 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
149 fn test_parse_github_urlsrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_parse_github_urls().() {
150 let urls = &[
151 "https://github.com/dandavison/delta.git",
152 "https://github.com/dandavison/delta",
153 "[email protected]:dandavison/delta.git",
154 "[email protected]:dandavison/delta",
155 "github.com:dandavison/delta.git",
156 "github.com:dandavison/delta",
157 ];
158 for url in urls {
159 let parsed = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::from_strrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]from_str().(url);
160 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
161 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
162 parsed.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
163 GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::GitHubrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub# {
164 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub#slug.: "dandavison/delta".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
165 }
166 );
167 }
168 }
169
170 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
171 fn test_format_github_commit_linkrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_format_github_commit_link().() {
172 let repo = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::GitHubrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub# {
173 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitHub#slug.: "dandavison/delta".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
174 };
175 let commit_hash = "d3b07384d113edec49eaa6238ad5ff00";
176 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
177 repo.format_commit_urlrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]format_commit_url().(commit_hash),
178 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://github.com/dandavison/delta/commit/{commit_hash}")
179 )
180 }
181
182 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
183 fn test_parse_gitlab_urlsrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_parse_gitlab_urls().() {
184 let urls = &[
185 (
186 "https://gitlab.com/proj/grp/subgrp/repo.git",
187 "proj/grp/subgrp/repo",
188 ),
189 ("https://gitlab.com/proj/grp/repo.git", "proj/grp/repo"),
190 ("https://gitlab.com/proj/repo.git", "proj/repo"),
191 ("https://gitlab.com/proj/repo", "proj/repo"),
192 (
193 "[email protected]:proj/grp/subgrp/repo.git",
194 "proj/grp/subgrp/repo",
195 ),
196 ("[email protected]:proj/repo.git", "proj/repo"),
197 ("[email protected]:proj/repo", "proj/repo"),
198 ("gitlab.com:proj/grp/repo.git", "proj/grp/repo"),
199 ("gitlab.com:proj/repo.git", "proj/repo"),
200 ("gitlab.com:proj/repo", "proj/repo"),
201 ];
202
203 for (url, expected) in urls {
204 let parsed = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::from_strrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]from_str().(url);
205 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
206 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
207 parsed.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
208 GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::GitLabrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab# {
209 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab#slug.: expected.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
210 }
211 );
212 }
213 }
214
215 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
216 fn test_format_gitlab_commit_linkrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_format_gitlab_commit_link().() {
217 let repo = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::GitLabrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab# {
218 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#GitLab#slug.: "proj/grp/repo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
219 };
220 let commit_hash = "d3b07384d113edec49eaa6238ad5ff00";
221 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
222 repo.format_commit_urlrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]format_commit_url().(commit_hash),
223 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://gitlab.com/proj/grp/repo/-/commit/{commit_hash}")
224 )
225 }
226
227 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
228 fn test_parse_sourcehut_urlsrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_parse_sourcehut_urls().() {
229 let urls = &[
230 "https://git.sr.ht/~someuser/somerepo",
231 "[email protected]:~someuser/somerepo",
232 "git.sr.ht:~someuser/somerepo",
233 ];
234 for url in urls {
235 let parsed = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::from_strrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]from_str().(url);
236 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
237 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
238 parsed.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
239 GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::SourceHutrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut# {
240 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut#slug.: "~someuser/somerepo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
241 }
242 );
243 }
244 }
245
246 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
247 fn test_format_sourcehut_commit_linkrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_format_sourcehut_commit_link().() {
248 let repo = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::SourceHutrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut# {
249 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#SourceHut#slug.: "~someuser/somerepo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
250 };
251 let commit_hash = "df41ac86f08a40e64c76062fd67e238522c14990";
252 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
253 repo.format_commit_urlrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]format_commit_url().(commit_hash),
254 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://git.sr.ht/~someuser/somerepo/commit/{commit_hash}")
255 )
256 }
257
258 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
259 fn test_parse_codeberg_urlsrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_parse_codeberg_urls().() {
260 let urls = &[
261 "https://codeberg.org/someuser/somerepo.git",
262 "https://codeberg.org/someuser/somerepo",
263 "[email protected]:someuser/somerepo.git",
264 "[email protected]:someuser/somerepo",
265 "codeberg.org:someuser/somerepo.git",
266 "codeberg.org:someuser/somerepo",
267 ];
268 for url in urls {
269 let parsed = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::from_strrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo][FromStr]from_str().(url);
270 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
271 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
272 parsed.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
273 GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::Codebergrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg# {
274 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg#slug.: "someuser/somerepo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
275 }
276 );
277 }
278 }
279
280 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
281 fn test_format_codeberg_commit_linkrust-analyzer cargo git-delta 0.19.2 git_config/remote/tests/test_format_codeberg_commit_link().() {
282 let repo = GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::Codebergrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg# {
283 slugrust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#Codeberg#slug.: "dnkl/foot".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
284 };
285 let commit_hash = "1c072856ebf12419378c5098ad543c497197c6da";
286 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
287 repo.format_commit_urlrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]format_commit_url().(commit_hash),
288 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("https://codeberg.org/dnkl/foot/commit/{commit_hash}")
289 )
290 }
291 }