Skip to content

Commit

Permalink
Merge branch 'main' into ctrlc
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Feb 1, 2024
2 parents 4298dc1 + 0cb3988 commit 3f0c53f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions e2e/test_go_install
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ eval "$(mise activate bash --shims)"
mise use go@prefix:1.20

assert "mise x go:github.com/DarthSim/hivemind@v1.1.0 -- hivemind --version" "Hivemind version 1.1.0"
assert "mise x go:github.com/go-task/task/v3/cmd/task@v3.34.1 -- task --version" "Task version: v3.34.1 (h1:yAAxUM54zoaHv+OtDnGgkWSVeiRuaOCn1lPUXPQQA0o=)"

chmod -R u+w "$MISE_DATA_DIR/cache/go-"* || true
25 changes: 22 additions & 3 deletions src/forge/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ impl Forge for GoForge {
fn list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
let raw = cmd!("go", "list", "-m", "-versions", "-json", self.name()).read()?;
let mod_info: GoModInfo = serde_json::from_str(&raw)?;
Ok(mod_info.versions)
let mut mod_path = Some(self.name());

while let Some(cur_mod_path) = mod_path {
let raw =
cmd!("go", "list", "-m", "-versions", "-json", cur_mod_path).read()?;

let result = serde_json::from_str::<GoModInfo>(&raw);
if let Ok(mod_info) = result {
return Ok(mod_info.versions);
}

mod_path = trim_after_last_slash(cur_mod_path);
}

Err(eyre!("couldn't find module versions"))
})
.cloned()
}
Expand Down Expand Up @@ -62,6 +74,13 @@ impl GoForge {
}
}

fn trim_after_last_slash(s: &str) -> Option<&str> {
match s.rsplit_once('/') {
Some((new_path, _)) => Some(new_path),
None => None,
}
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct GoModInfo {
Expand Down

0 comments on commit 3f0c53f

Please sign in to comment.