GITv

Show the public repository index when signed out

Browse files
Author
Um9i vulgarmessiah@gmail.com
Date
22 Nov 2026, 14:33
Commit
0d0992e82d26
Parent
6a22d2a

3 files changed +22−16

@@ -872,9 +872,6 @@ fn view_index(signed_in: bool) -> View {
rows.push(Row { owner: owner.clone(), name: name.to_string(), head });
}
}
if rows.is_empty() && !signed_in {
return View::LoginRequired;
}
rows.sort_by_key(|row| Reverse(row.head.as_ref().and_then(|h| h.stamp.parse::<u64>().ok()).unwrap_or(0)));
let items: String = rows
.iter()
@@ -890,7 +887,9 @@ fn view_index(signed_in: bool) -> View {
)
})
.collect();
let listing = if items.is_empty() {
let listing = if items.is_empty() && !signed_in {
r#"<div class="panel empty"><h2>No public repositories yet</h2></div>"#.to_owned()
} else if items.is_empty() {
format!(
r#"<div class="panel empty"><h2>No repositories yet</h2><p>Push to a new name and GITv creates the repository.</p>
<code>git push git@{HOST}:um9i/my-project.git main</code></div>"#
@@ -38,7 +38,7 @@ mod signed_out {
#[test]
fn nothing_private_is_reachable() {
let s = Server::start_signed_out(repos());
for path in ["/", "/ada/notes", "/ada/notes/raw?path=x", "/ada/notes/log", "/account", "/nope", "/login/../"] {
for path in ["/ada/notes", "/ada/notes/raw?path=x", "/ada/notes/log", "/account", "/nope", "/login/../"] {
let response = s.get_signed_out(path);
assert_eq!(response.status, 303, "{path} was served");
assert!(response.header("location").starts_with("/login"), "{path}");
@@ -220,7 +220,7 @@ mod signing_in {
fn a_forged_cookie_is_not_a_session() {
let mut s = Server::start_signed_out(repos());
s.cookie = Some("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".into());
assert_eq!(s.get("/").status, 303);
assert_eq!(s.get("/account").status, 303);
}
}
@@ -239,14 +239,14 @@ mod signing_out {
let response = s.post("/logout", &[("csrf", &csrf(&s))]);
assert_eq!((response.status, response.header("location")), (303, "/login"));
assert!(response.header("set-cookie").contains("Max-Age=0"));
assert_eq!(s.get("/").status, 303, "the old cookie still works");
assert_eq!(s.get("/account").status, 303, "the old cookie still works");
}
#[test]
fn needs_the_form_token() {
let s = Server::start(repos());
assert_eq!(s.post("/logout", &[("csrf", "forged")]).status, 403);
assert_eq!(s.get("/").status, 200, "a forged sign-out ended the session");
assert_eq!(s.get("/account").status, 200, "a forged sign-out ended the session");
}
}
@@ -276,7 +276,7 @@ mod changing_the_password {
);
assert_eq!(response.status, 200, "{}", response.text());
assert!(response.text().contains("Password changed."));
assert_eq!(s.get("/").status, 200);
assert_eq!(s.get("/account").status, 200);
}
#[test]
@@ -302,12 +302,12 @@ mod changing_the_password {
let mut second = Server::start_signed_out(repos());
second.port = first.port;
second.cookie = session_cookie(&response);
assert_eq!(second.get("/").status, 200);
assert_eq!(second.get("/account").status, 200);
let new = "yet another new password";
let response = change(&first, &csrf(&first), &first.account.password, new, new, &first.account.code(1));
assert_eq!(response.status, 200, "{}", response.text());
assert_eq!(second.get("/").status, 303, "the other session survived");
assert_eq!(first.get("/").status, 200, "this session was ended");
assert_eq!(second.get("/account").status, 303, "the other session survived");
assert_eq!(first.get("/account").status, 200, "this session was ended");
}
#[test]
@@ -367,12 +367,12 @@ mod changing_the_password {
#[test]
fn on_the_server_signs_everyone_out() {
let s = Server::start(repos());
assert_eq!(s.get("/").status, 200);
assert_eq!(s.get("/account").status, 200);
// What `gitv-web password` does: rewrite the account file with a new password.
let mut credentials = gitv::auth::Credentials::load(&s.account.file).unwrap();
credentials.set_password("changed on the server").unwrap();
credentials.save(&s.account.file, None).unwrap();
assert_eq!(s.get("/").status, 303);
assert_eq!(s.get("/account").status, 303);
}
}
@@ -426,7 +426,7 @@ mod setup {
.output()
.unwrap();
assert!(out.status.success(), "{}", stderr(&out));
assert_eq!(s.get("/").status, 303);
assert_eq!(s.get("/account").status, 303);
}
#[test]
@@ -457,7 +457,10 @@ mod setup {
fn without_an_account_the_site_says_how_to_set_one_up() {
let s = Server::start_signed_out(repos());
std::fs::remove_file(&s.account.file).unwrap();
let response = s.get_signed_out("/");
let index = s.get_signed_out("/");
assert_eq!(index.status, 200);
assert!(index.text().contains("No public repositories yet"));
let response = s.get_signed_out("/account");
assert_eq!(response.status, 503);
assert!(response.text().contains("gitv-web setup"));
}
@@ -797,6 +797,10 @@ fn public_web_clone_and_visibility_changes() {
let url = format!("http://127.0.0.1:{}/ada/sharing", server.port);
let refs = "/ada/sharing/info/refs?service=git-upload-pack";
assert_eq!(server.get_signed_out(refs).status, 404);
let empty = server.get_signed_out("/");
assert_eq!(empty.status, 200);
assert!(empty.text().contains("No public repositories yet"));
assert!(!empty.text().contains("/ada/"));
assert!(host.ssh("ada", "visibility sharing public").status.success());
let index = server.get_signed_out("/").text();
assert!(index.contains("/ada/sharing/tree"));