| | @@ -32,7 +32,9 @@ use crate::{ |
| 32 | 32 | }; |
| 33 | 33 | |
| 34 | 34 | use super::{ |
| 35 | | − context::{current_actor, location, memberships, orgs, repos, server_error, storage}, |
| 35 | + context::{ |
| 36 | + current_actor, location, memberships, orgs, public_origin, repos, server_error, storage, |
| 37 | + }, |
| 36 | 38 | profile::profile_for, |
| 37 | 39 | }; |
| 38 | 40 | |
| | @@ -163,6 +165,7 @@ async fn create(cx: &Cx, Form(submitted): Form<CreateForm>) -> Result { |
| 163 | 165 | #[page("/{handle}/repos/{name}")] |
| 164 | 166 | async fn repo_page(cx: &Cx) -> Result { |
| 165 | 167 | let repo = repo_for(cx).await?; |
| 168 | + let clone = clone_url_for(cx, &repo); |
| 166 | 169 | |
| 167 | 170 | view! { |
| 168 | 171 | <header class="mb-8"> |
| | @@ -188,9 +191,9 @@ async fn repo_page(cx: &Cx) -> Result { |
| 188 | 191 | }?) |
| 189 | 192 | </header> |
| 190 | 193 | |
| 191 | | − // Deliberately no clone command: the git protocol arrives in Milestone 4, and |
| 192 | | − // printing an instruction that fails is worse than printing nothing. |
| 193 | | − <div class="rounded-lg border border-border px-4 py-10 text-center"> |
| 194 | + clone_url(url: clone.as_str()) |
| 195 | + |
| 196 | + <div class="mt-6 rounded-lg border border-border px-4 py-10 text-center"> |
| 194 | 197 | <p class="text-sm text-muted-foreground">"This repository is empty."</p> |
| 195 | 198 | </div> |
| 196 | 199 | } |
| | @@ -285,6 +288,36 @@ async fn new_repo_form( |
| 285 | 288 | /// |
| 286 | 289 | /// One empty state serves both "no repositories" and "none you may see" — a distinct |
| 287 | 290 | /// message for the second would leak that private repositories exist. |
| 291 | +/// The URL to clone this repository from. |
| 292 | +/// |
| 293 | +/// Built from the origin the page is being served on, so it is correct wherever the |
| 294 | +/// instance is deployed without anything having to be configured. A private repository |
| 295 | +/// gets the same URL: cloning it needs a token, not a different address. |
| 296 | +fn clone_url_for(cx: &Cx, repo: &RepoView) -> String { |
| 297 | + format!( |
| 298 | + "{}/{}/repos/{}.git", |
| 299 | + public_origin(cx), |
| 300 | + repo.handle, |
| 301 | + repo.name |
| 302 | + ) |
| 303 | +} |
| 304 | + |
| 305 | +/// The clone address, ready to copy. |
| 306 | +/// |
| 307 | +/// Shown for every repository a viewer can see, including an empty one — an empty |
| 308 | +/// repository is exactly when someone needs this, because it is what they push to. |
| 309 | +#[component] |
| 310 | +async fn clone_url(url: &str) -> Result { |
| 311 | + view! { |
| 312 | + <div class="mt-6"> |
| 313 | + <p class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 314 | + "Clone" |
| 315 | + </p> |
| 316 | + <pre class="mt-2 overflow-x-auto rounded-lg border border-border bg-muted px-4 py-3 font-mono text-sm">"git clone " (url)</pre> |
| 317 | + </div> |
| 318 | + } |
| 319 | +} |
| 320 | + |
| 288 | 321 | #[component] |
| 289 | 322 | pub(super) async fn repo_list(handle: &str, repos: &[RepoSummary]) -> Result { |
| 290 | 323 | view! { |