submodule add probes an URL with the environment's credentials (OXY_TOKEN, OXY_CA) as a clone does, and reports the Oxygen error when Git cannot clone it either 0955469ac0e1
closes #8
- Author
- Andy McCall @andymccall <[email protected]>
- When
- · 2026-09-28 18:48 UTC
- Signature
- ✔ signed by Andy McCall
- Hash
0955469ac0e13cbb7e9e0cfdad58aedd5cb3bb766fc588e81b132b650bce06e4- Depends on
- 4dee277c327a 75167672ebcd
- Depended on by
- a07f60a37fb2
- In bookmarks
- agents-in-readme bare-hashes carried-not-removed carry-identical doctor-trust identical-sides keyless-tags main merge-remote-bookmark only-help-103 paths-for-resolutions-and-amend push-notes show-stat subrepo-pin-state switch-says
- In tags
- v0.1.0 v0.10.0 v0.11.0 v0.2.0 v0.3.0 v0.3.1 v0.4.0 v0.4.1 v0.4.2 v0.4.3 v0.4.4 v0.4.5 v0.4.6 v0.5.0 v0.5.1 v0.6.0 v0.7.0 v0.8.0 v0.9.0
- Edits
- 7 atoms, 0 tree operations, 1 file
Browse the tree at this change
modified crates/oxy-core/src/repo/subrepos.rs +23 −6
| … | 76 unchanged lines |
||
| 77 | 77 | } |
|
| 78 | 78 | ||
| 79 | 79 | /// Whether `url` names an Oxygen repository (else it is taken to be Git). |
|
| 80 | - | fn is_oxy_url(url: &str) -> bool { |
|
| 80 | + | /// Whether `url` is an Oxygen repository, probed with the environment's |
|
| 81 | + | /// credentials (`OXY_TOKEN`, `OXY_CA`) as a clone would use them; with the |
|
| 82 | + | /// probe's error when it is not, to report if Git cannot clone it either. |
|
| 83 | + | fn probe_oxy_url(url: &str) -> std::result::Result<(), String> { |
|
| 81 | 84 | if url.starts_with("http://") || url.starts_with("https://") { |
|
| 82 | - | return crate::protocol::open_remote(url, &RemoteOptions::default()) |
|
| 85 | + | let options = RemoteOptions { |
|
| 86 | + | token: std::env::var("OXY_TOKEN").ok(), |
|
| 87 | + | ca: std::env::var("OXY_CA").ok().map(std::path::PathBuf::from), |
|
| 88 | + | repo_id: None, |
|
| 89 | + | }; |
|
| 90 | + | return crate::protocol::open_remote(url, &options) |
|
| 83 | 91 | .and_then(|r| r.repo_id()) |
|
| 84 | - | .is_ok(); |
|
| 92 | + | .map(|_| ()) |
|
| 93 | + | .map_err(|e| e.to_string()); |
|
| 85 | 94 | } |
|
| 86 | 95 | let p = Path::new(url.strip_prefix("file://").unwrap_or(url)); |
|
| 87 | - | p.join(OXY_DIR).exists() |
|
| 96 | + | if p.join(OXY_DIR).exists() { |
|
| 97 | + | Ok(()) |
|
| 98 | + | } else { |
|
| 99 | + | Err(format!("{} has no {OXY_DIR} directory", p.display())) |
|
| 100 | + | } |
|
| 88 | 101 | } |
|
| 89 | 102 | ||
| 90 | 103 | impl Repo { |
|
| … | 162 unchanged lines |
||
| 253 | 266 | if let Some(parent) = dir.parent() { |
|
| 254 | 267 | fs::create_dir_all(parent)?; |
|
| 255 | 268 | } |
|
| 256 | - | let git = !is_oxy_url(url); |
|
| 269 | + | let probe = probe_oxy_url(url); |
|
| 270 | + | let git = probe.is_err(); |
|
| 257 | 271 | if git { |
|
| 258 | 272 | let mut cmd = Command::new("git"); |
|
| 259 | 273 | cmd.args(["clone", "-q"]); |
|
| … | 6 unchanged lines |
||
| 266 | 280 | .status() |
|
| 267 | 281 | .map_err(|e| RepoError::Msg(format!("running git: {e}")))?; |
|
| 268 | 282 | if !status.success() { |
|
| 269 | - | return fail(format!("git clone {url} failed")); |
|
| 283 | + | let oxy_error = probe.err().unwrap_or_default(); |
|
| 284 | + | return fail(format!( |
|
| 285 | + | "git clone {url} failed; as an Oxygen repository: {oxy_error}" |
|
| 286 | + | )); |
|
| 270 | 287 | } |
|
| 271 | 288 | } else { |
|
| 272 | 289 | let _ = fs::remove_dir(&dir); |
|
| … | 78 unchanged lines |