diff --git a/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs b/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs index 573257d..0559722 100644 --- a/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_rename_e2e.rs @@ -250,15 +250,15 @@ async fn repo_rename_end_to_end() { 200 ); - // The old web URL 301s to the same path under the new name, and keeps the query. + // The old web URL 307s to the same path under the new name, and keeps the query. let old_tree = http.get("/bob/pub/tree/main/src", None).await; - assert_eq!(old_tree.status, 301, "old tree URL"); + assert_eq!(old_tree.status, 307, "old tree URL"); assert_eq!( old_tree.header(LOCATION).as_deref(), Some("/bob/newpub/tree/main/src") ); let old_query = http.get("/bob/pub?tab=x", None).await; - assert_eq!(old_query.status, 301, "old repo URL with query"); + assert_eq!(old_query.status, 307, "old repo URL with query"); assert_eq!( old_query.header(LOCATION).as_deref(), Some("/bob/newpub?tab=x") @@ -407,7 +407,7 @@ async fn repo_rename_end_to_end() { 200 ); let moved = http.get("/bob/newpub/tree/main/src", None).await; - assert_eq!(moved.status, 301, "old owner and name"); + assert_eq!(moved.status, 307, "old owner and name"); assert_eq!( moved.header(LOCATION).as_deref(), Some("/carol/newpub/tree/main/src") @@ -416,7 +416,7 @@ async fn repo_rename_end_to_end() { // A chain: bob/pub -> bob/newpub -> carol/newpub. The oldest name still redirects, and its // clone URL still works for an anonymous fetch of this public repo. let chained = http.get("/bob/pub/tree/main/src", None).await; - assert_eq!(chained.status, 301, "chained redirect"); + assert_eq!(chained.status, 307, "chained redirect"); assert_eq!( chained.header(LOCATION).as_deref(), Some("/carol/newpub/tree/main/src") @@ -443,11 +443,11 @@ async fn repo_rename_end_to_end() { assert_eq!(taken_over.status, 200, "new repo takes over the old name"); assert_eq!( http.get("/bob/newpub", None).await.status, - 301, + 307, "the other old name still redirects" ); - // A private repo renamed away: an anonymous or unrelated viewer gets 404, the owner gets 301. + // A private repo renamed away: an anonymous or unrelated viewer gets 404, the owner gets 307. let csrf = csrf_for(&http, &bob).await; let secret_rename = http .post_form( @@ -469,7 +469,7 @@ async fn repo_rename_end_to_end() { "missing repo looks the same" ); let owner_view = http.get("/bob/secret", Some(&bob)).await; - assert_eq!(owner_view.status, 301, "owner follows the redirect"); + assert_eq!(owner_view.status, 307, "owner follows the redirect"); assert_eq!(owner_view.header(LOCATION).as_deref(), Some("/bob/secret2")); // Git clients get the same answer for a hidden repo as for a missing one. let hidden_git = http diff --git a/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs b/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs index 26b01d9..d3e6875 100644 --- a/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_settings_e2e.rs @@ -523,11 +523,22 @@ async fn branch_protection_end_to_end() { let updated = http .post_form( "/bob/app/settings/branches", - &[("csrf", &owner_csrf), ("pattern", "main")], + &[("csrf", &owner_csrf), ("pattern", "main"), ("existing", "1")], Some(&bob), ) .await; assert_eq!(updated.status, 303, "update rule: {}", updated.body); + + // Adding a new rule for a pattern that has one is refused instead of overwriting it. + let duplicate = http + .post_form( + "/bob/app/settings/branches", + &[("csrf", &owner_csrf), ("pattern", "main")], + Some(&bob), + ) + .await; + assert_eq!(duplicate.status, 200, "duplicate rule re-renders the page"); + assert!(duplicate.body.contains("already exists"), "duplicate rule names the clash"); let page = http .get("/bob/app/settings?section=branches", Some(&bob)) .await; diff --git a/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs b/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs index e92e02c..01484a5 100644 --- a/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs +++ b/crates/forge-e2e/tests/e2e/repo_transfer_e2e.rs @@ -185,5 +185,5 @@ async fn repo_transfer_offers_declines_cancels_and_org_targets() { assert_eq!(accepted.header(LOCATION).as_deref(), Some("/acme/pub")); assert_eq!(http.get("/acme/pub", Some(&bob)).await.status, 200); let old = http.get("/bob/pub", Some(&bob)).await; - assert_eq!(old.status, 301, "old owner and name redirect"); + assert_eq!(old.status, 307, "old owner and name redirect"); } diff --git a/crates/forge-web-base/src/i18n/repo_admin.rs b/crates/forge-web-base/src/i18n/repo_admin.rs index cb41e0f..a752e5b 100644 --- a/crates/forge-web-base/src/i18n/repo_admin.rs +++ b/crates/forge-web-base/src/i18n/repo_admin.rs @@ -359,9 +359,9 @@ pub fn t(lang: Lang, key: K) -> &'static str { (PatternHelpB, Tr) => " tek yol parçası içinde eşleşir, ", (PatternHelpC, En) => " matches across ", (PatternHelpC, Tr) => " ise ", - (PatternHelpD, En) => ". Saving an existing pattern updates its rule.", + (PatternHelpD, En) => ".", (PatternHelpD, Tr) => { - " işaretini de aşarak eşleşir. Var olan bir deseni kaydetmek, kuralını günceller." + " işaretini de aşarak eşleşir." } (PendingTransfers, En) => "Pending transfers", (PendingTransfers, Tr) => "Bekleyen devirler", diff --git a/crates/forge-web/src/pages/repo_ctx.rs b/crates/forge-web/src/pages/repo_ctx.rs index be2b270..e512231 100644 --- a/crates/forge-web/src/pages/repo_ctx.rs +++ b/crates/forge-web/src/pages/repo_ctx.rs @@ -1,6 +1,6 @@ //! Shared lookup for every repo page: resolve owner/name, authorize Read for the viewer, //! and return 404 for both missing and hidden repos so private repos are never revealed. -//! A past owner/name (a redirect left by a rename or transfer) gets a 301 to the current URL +//! A past owner/name (a redirect left by a rename or transfer) gets a 307 to the current URL //! when the viewer may read the repo it now points at. use std::path::PathBuf; @@ -8,7 +8,7 @@ use std::path::PathBuf; use forge_core::authz::{Action, authorize}; use forge_core::{Repo, Role, Session, Store, User, Visibility, WatchLevel}; use forge_git::repo::repo_path; -use http::{HeaderValue, header::LOCATION}; +use http::{HeaderValue, header::{CACHE_CONTROL, LOCATION}}; use topcoat::Result; use topcoat::context::{Cx, app_context}; use topcoat::router::error::not_found; @@ -125,7 +125,7 @@ pub struct WatchButton { } /// Raised by `load_repo` when the requested owner/name is a past name of a repo the viewer may -/// read. The `repo_moved` layer turns it into a 301 to `location`. +/// read. The `repo_moved` layer turns it into a 307 to `location`. #[derive(Debug)] pub struct RepoMoved { pub location: String, @@ -414,7 +414,7 @@ async fn moved_location( ))) } -/// Wraps every request (no path) so a `RepoMoved` error becomes a 301. Registered explicitly on the +/// Wraps every request (no path) so a `RepoMoved` error becomes a 307. Registered explicitly on the /// public router in `boot.rs`: a `#[layer("/")]` would clash with the security-headers layer. pub struct RepoMovedLayer; @@ -428,7 +428,7 @@ impl Layer for RepoMovedLayer { } } -/// Turns a `RepoMoved` error from a handler into a 301 with the new location, and a `RawDownload` +/// Turns a `RepoMoved` error from a handler into a 307 with the new location, and a `RawDownload` /// into its plain-text response. Other errors pass through unchanged. async fn repo_moved(cx: &Cx, body: Body, next: Next<'_>) -> Result { let error = match next.run(cx, body).await { @@ -444,13 +444,18 @@ async fn repo_moved(cx: &Cx, body: Body, next: Next<'_>) -> Result { match error.downcast_ref::() { Some(moved) => { let mut response = Response::new(Body::empty()); - *response.status_mut() = StatusCode::MOVED_PERMANENTLY; + // Temporary and uncached: an old name can be taken by a new repo later, and a browser + // that cached a 301 would keep sending its visitors to the renamed repo. + *response.status_mut() = StatusCode::TEMPORARY_REDIRECT; // Owner and repo names are plain ASCII and the query came from a valid URI, so this // only fails on a corrupt location; a 404 is the safe answer then. let Ok(location) = HeaderValue::from_str(&moved.location) else { return Err(not_found().into()); }; response.headers_mut().insert(LOCATION, location); + response + .headers_mut() + .insert(CACHE_CONTROL, HeaderValue::from_static("no-store")); Ok(response) } None => Err(error), diff --git a/crates/forge-web/src/pages/repo_settings.rs b/crates/forge-web/src/pages/repo_settings.rs index 5376bd0..edbc576 100644 --- a/crates/forge-web/src/pages/repo_settings.rs +++ b/crates/forge-web/src/pages/repo_settings.rs @@ -153,6 +153,10 @@ struct BranchForm { /// Required check contexts, separated by commas or new lines. #[serde(default)] required_checks: String, + /// Set by an existing rule's form, whose pattern is fixed. Without it the form adds a rule, and + /// a pattern that already has one is refused rather than overwriting it. + #[serde(default)] + existing: Option, } #[derive(Deserialize)] @@ -609,6 +613,7 @@ async fn branch_rule_form( require_merge_queue, required_checks, error, + is_new: _, } = draft; // Field ids are per rule, so two open rule forms never share an id. let prefix = match &rule_id { @@ -624,11 +629,23 @@ async fn branch_rule_form( alert(message: message.as_str()) } -
- - -

(g::t(lang, K::PatternHelpA))"*"(g::t(lang, K::PatternHelpB))"**"(g::t(lang, K::PatternHelpC))"/"(g::t(lang, K::PatternHelpD))

-
+ // An existing rule's pattern is fixed: this form only changes what the rule does. A + // different pattern is a new rule, added from the New rule line. + if rule_id.is_some() { + + +
+ (g::t(lang, K::BranchPattern)) + (pattern.as_str()) +

(passkeys::s(lang, "For another branch, add a new rule.", "Başka bir dal için yeni bir kural ekle."))

+
+ } else { +
+ + +

(g::t(lang, K::PatternHelpA))"*"(g::t(lang, K::PatternHelpB))"**"(g::t(lang, K::PatternHelpC))"/"(g::t(lang, K::PatternHelpD))

+
+ } // Each group is a field: its name in the label column, its boxes in the control column, each // box with its note beside it.
@@ -696,7 +713,11 @@ async fn branch_rule_form( }
- + if rule_id.is_some() { + + } else { + + }
@@ -722,6 +743,8 @@ struct RuleDraft { require_merge_queue: bool, required_checks: String, error: Option, + /// True for the New rule form's draft, so a refused new rule never opens an existing rule's card. + is_new: bool, } impl RuleDraft { @@ -738,6 +761,7 @@ impl RuleDraft { require_merge_queue: rule.require_merge_queue, required_checks: rule.required_checks.join(", "), error: None, + is_new: false, } } @@ -754,6 +778,7 @@ impl RuleDraft { require_merge_queue: false, required_checks: String::new(), error: None, + is_new: true, } } } @@ -803,7 +828,7 @@ async fn settings_body( let mut cards = Vec::with_capacity(rules.len()); for rule in rules { let card_draft = match draft.take() { - Some(d) if d.error.is_some() && d.pattern == rule.pattern => d, + Some(d) if d.error.is_some() && !d.is_new && d.pattern == rule.pattern => d, other => { draft = other; RuleDraft::from_rule(&rule) @@ -1261,10 +1286,25 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form) -> Result(cx) + .store + .list_branch_rules(&ctx.repo.id) + .await? + .iter() + .any(|rule| rule.pattern == pattern); + let checked = if taken { + Err(passkeys::s( + lang, + "A rule for this pattern already exists. Pick it in the list to change it.", + "Bu desen için zaten bir kural var. Değiştirmek için listeden onu seç.", + ) + .to_owned()) + } else { + validate_pattern(&pattern).map_err(|e| e.to_string()) + }; + let flags = match checked.and_then(|()| parse_rule_flags(lang, &form)) { Ok(flags) => flags, Err(message) => { let rules = app_context::(cx) @@ -1285,6 +1325,7 @@ async fn settings_branch_save(cx: &Cx, Form(form): Form) -> Result(cx) @@ -1439,7 +1480,7 @@ mod tests { let (status, _) = post_rule( &app, &cookie, - &[("pattern", "main"), ("required_approvals", "")], + &[("pattern", "main"), ("existing", "1"), ("required_approvals", "")], ) .await; assert_eq!(status, 303); @@ -1454,7 +1495,7 @@ mod tests { &app, &cookie, &[ - ("pattern", "main"), + ("pattern", "main"), ("existing", "1"), ("required_approvals", "21"), ("restrict_push", "on"), ], @@ -1473,7 +1514,7 @@ mod tests { let (status, body) = post_rule( &app, &cookie, - &[("pattern", "main"), ("required_approvals", "two")], + &[("pattern", "main"), ("existing", "1"), ("required_approvals", "two")], ) .await; assert_eq!(status, 200); diff --git a/docs/ui-language.md b/docs/ui-language.md index f1838b4..6b39938 100644 --- a/docs/ui-language.md +++ b/docs/ui-language.md @@ -80,7 +80,7 @@ no `margin-left:auto`, no `justify-content:space-between`, no second column at t - **Time range**: every log has a When filter (Any time, Last hour, Last 24 hours, Last 7 days, Last 30 days, Today, Dates…). Dates… shows From and To day fields in the viewer's timezone, and the tools row starts with the count of entries that match, so "how many sign-ins last week" is one glance. -- **Tool**: `.act`, a quiet word (14px, dim, radius 12). `.act.danger` for destructive. This is what goes in +- **Tool**: `.act`, a word in the accent's ink (14px, 600, radius 12), never the dim colour of a hint. `.act.danger` for destructive. This is what goes in tools rows, in rows and in `.acts`. - `reveal(label, id, open)`: a tool that opens its form in place. `open` when a form came back with an error. In a `.fields` form its word starts on the controls' edge. What should not be one click away diff --git a/scripts/audit/shoot.py b/scripts/audit/shoot.py index 6f31ec9..8e1bdff 100755 --- a/scripts/audit/shoot.py +++ b/scripts/audit/shoot.py @@ -446,6 +446,8 @@ def concrete(pat): res += [(f"/{o}/{s['private_repo']}", "private"), (f"/{s['org']}/{s['org_repo']}", "org-empty")] if pat == "/{username}": res += [(f"/{s['org']}", "org"), (f"/{o}?tab=stars", "stars"), (f"/{o}?tab=repositories", "repos")] + if pat == "/{owner}/{repo}/settings": + res += [(f"/{o}/{r}/settings?section=branches", "branches")] if pat == "/{owner}/{repo}/issues": res += [(f"/{o}/{r}/issues?state=closed", "closed")] if pat == "/{owner}/{repo}/pulls/{number}": diff --git a/style/_browse.scss b/style/_browse.scss index 11f749f..016b12d 100644 --- a/style/_browse.scss +++ b/style/_browse.scss @@ -261,6 +261,7 @@ dialog.finder { } .finder-input { + flex: none; width: 100%; height: var(--control-h); box-sizing: border-box; @@ -271,6 +272,8 @@ dialog.finder { margin: 0; padding: 0; list-style: none; + flex: 1 1 auto; + min-height: 0; overflow-y: auto; max-height: 50vh; font-family: var(--mono); diff --git a/style/_min_code.scss b/style/_min_code.scss index b298120..71f4126 100644 --- a/style/_min_code.scss +++ b/style/_min_code.scss @@ -57,3 +57,17 @@ main .repo-grid.repo-home .browse-bar .finder-open { .repo-strip .strip-chips { margin-left: 0; } + +// Browse files keeps the row's spacing: its padding is for the hover shape, not extra room, so a +// wrapped one starts on the row's text edge like the facts above it. +.commits-r > a.act { + margin-left: -10px; +} + +// On a phone every commit row has the same two lines: the subject, then who, when, the hash, its +// checks and Browse files. +@media (max-width: 700px) { + .commits-r > .name { + flex-basis: 100%; + } +} diff --git a/style/_one.scss b/style/_one.scss index 199964b..890cb3d 100644 --- a/style/_one.scss +++ b/style/_one.scss @@ -292,7 +292,7 @@ button.icon-btn, } } -// An action inside content: a quiet word that lights up when pointed at. +// An action inside content: a word in the accent's ink, so it never reads as a hint or a heading. a.act, span.act, @@ -309,11 +309,11 @@ button.link-button, border-radius: 12px; background: none; box-shadow: none; - color: var(--muted); + color: var(--accent-ink); cursor: pointer; font-family: var(--font); font-size: 14px; - font-weight: 500; + font-weight: 600; line-height: 1; text-decoration: none; white-space: nowrap; @@ -321,7 +321,7 @@ button.link-button, &:hover { border: 0; background: var(--surface-2); - color: var(--text); + color: var(--accent-ink); text-decoration: none; } @@ -1446,6 +1446,7 @@ a.line:hover .name, .sheet > .sec > .line, .sheet > .sec > .commits-list > .line, +.sheet > .sec > .commits-list > .row-open > .line, .sheet > .sec > .row-open > .line { margin: 0 -18px; padding-right: 18px; @@ -1470,7 +1471,8 @@ a.line:hover .name, border-bottom: 1px solid var(--border); } -.sheet > .sec > .row-open > .opened { +.sheet > .sec > .row-open > .opened, +.sheet > .sec > .commits-list > .row-open > .opened { margin: 0 -18px; padding-right: 18px; padding-left: 18px; @@ -3636,3 +3638,10 @@ details.log-group { padding-bottom: 4px; } } + +// A fixed value in a field's control column (an existing branch rule's pattern) stands on its label's line. +.field > .field-value { + padding-top: 8px; + font-size: 15px; + line-height: 22px; +}