diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 2e0f2e7e1..9bd590c9b 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -1735,9 +1735,24 @@ impl RunCommand { if !cfg!(unix) || matches!(target_path.try_exists(), Ok(false)) { let mut url = DisplaySafeUrl::parse(&target.to_string_lossy())?; + let client = client_builder.build(); + let mut response = client + .for_host(&url) + .get(Url::from(url.clone())) + .send() + .await?; + // If it's a Gist URL, use the GitHub API to get the raw URL. - if url.host_str() == Some("gist.github.com") { - url = resolve_gist_url(&url, &client_builder).await?; + if response.url().host_str() == Some("gist.github.com") { + url = + resolve_gist_url(DisplaySafeUrl::ref_cast(response.url()), &client_builder) + .await?; + + response = client + .for_host(&url) + .get(Url::from(url.clone())) + .send() + .await?; } let file_stem = url @@ -1750,13 +1765,6 @@ impl RunCommand { .suffix(".py") .tempfile()?; - let client = client_builder.build(); - let response = client - .for_host(&url) - .get(Url::from(url.clone())) - .send() - .await?; - // Stream the response to the file. let mut writer = file.as_file(); let mut reader = response.bytes_stream();