upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/git/nostr_url.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs
index c7e1bf2..ea8d221 100644
--- a/src/lib/git/nostr_url.rs
+++ b/src/lib/git/nostr_url.rs
@@ -12,9 +12,11 @@ pub enum ServerProtocol {
12 Http, 12 Http,
13 Git, 13 Git,
14 Ftp, 14 Ftp,
15 Local, 15 Filesystem,
16 #[default] 16 #[default]
17 Unspecified, 17 Unspecified,
18 UnauthHttps, // used for read to enable non-interactive failures over https
19 UnauthHttp, // used for read to enable non-interactive failures over https
18} 20}
19impl fmt::Display for ServerProtocol { 21impl fmt::Display for ServerProtocol {
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 22 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -24,8 +26,10 @@ impl fmt::Display for ServerProtocol {
24 ServerProtocol::Ftp => write!(f, "ftp"), 26 ServerProtocol::Ftp => write!(f, "ftp"),
25 ServerProtocol::Ssh => write!(f, "ssh"), 27 ServerProtocol::Ssh => write!(f, "ssh"),
26 ServerProtocol::Git => write!(f, "git"), 28 ServerProtocol::Git => write!(f, "git"),
27 ServerProtocol::Local => write!(f, "local"), 29 ServerProtocol::Filesystem => write!(f, "filesystem"),
28 ServerProtocol::Unspecified => write!(f, "unsepcified"), 30 ServerProtocol::Unspecified => write!(f, "unsepcified"),
31 ServerProtocol::UnauthHttps => write!(f, "unauthenticated https"),
32 ServerProtocol::UnauthHttp => write!(f, "unauthenticated http"),
29 } 33 }
30 } 34 }
31} 35}
@@ -168,7 +172,7 @@ impl FromStr for CloneUrl {
168 if s.starts_with('/') || s.starts_with("./") || s.starts_with("../") { 172 if s.starts_with('/') || s.starts_with("./") || s.starts_with("../") {
169 return Ok(Self { 173 return Ok(Self {
170 original_string: s.to_string(), 174 original_string: s.to_string(),
171 protocol: ServerProtocol::Local, 175 protocol: ServerProtocol::Filesystem,
172 ..CloneUrl::default() 176 ..CloneUrl::default()
173 }); 177 });
174 } 178 }
@@ -248,13 +252,16 @@ fn contains_port(s: &str) -> bool {
248impl CloneUrl { 252impl CloneUrl {
249 pub fn format_as(&self, protocol: &ServerProtocol, user: &Option<String>) -> Result<String> { 253 pub fn format_as(&self, protocol: &ServerProtocol, user: &Option<String>) -> Result<String> {
250 // Check for incompatible protocol conversions 254 // Check for incompatible protocol conversions
251 if *protocol == ServerProtocol::Local { 255 if *protocol == ServerProtocol::Filesystem {
252 if self.protocol == ServerProtocol::Local { 256 if self.protocol == ServerProtocol::Filesystem {
253 // If converting from Local to Local, return the original string 257 // If converting from Filesystem to Filesystem, return the original string
254 return Ok(self.original_string.clone()); 258 return Ok(self.original_string.clone());
255 } else { 259 } else {
256 // If converting to Local from any other protocol, return an error 260 // If converting to Filesystem from any other protocol, return an error
257 bail!("Cannot convert to Local protocol from {:?}", self.protocol); 261 bail!(
262 "Cannot convert to Filesystem protocol from {:?}",
263 self.protocol
264 );
258 } 265 }
259 } 266 }
260 267
@@ -262,7 +269,9 @@ impl CloneUrl {
262 "{}{}", 269 "{}{}",
263 match protocol { 270 match protocol {
264 ServerProtocol::Https => "https://", 271 ServerProtocol::Https => "https://",
272 ServerProtocol::UnauthHttps => "https://",
265 ServerProtocol::Http => "http://", 273 ServerProtocol::Http => "http://",
274 ServerProtocol::UnauthHttp => "http://",
266 ServerProtocol::Git => "git://", 275 ServerProtocol::Git => "git://",
267 ServerProtocol::Ftp => "ftp://", 276 ServerProtocol::Ftp => "ftp://",
268 ServerProtocol::Ssh => "ssh://", 277 ServerProtocol::Ssh => "ssh://",