@@ -21,6 +21,7 @@ import ( |
| 21 | "github.com/tenseleyFlow/shithub/internal/auth/throttle" | 21 | "github.com/tenseleyFlow/shithub/internal/auth/throttle" |
| 22 | "github.com/tenseleyFlow/shithub/internal/infra/storage" | 22 | "github.com/tenseleyFlow/shithub/internal/infra/storage" |
| 23 | "github.com/tenseleyFlow/shithub/internal/repos" | 23 | "github.com/tenseleyFlow/shithub/internal/repos" |
| | 24 | + repogit "github.com/tenseleyFlow/shithub/internal/repos/git" |
| 24 | reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc" | 25 | reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc" |
| 25 | "github.com/tenseleyFlow/shithub/internal/repos/templates" | 26 | "github.com/tenseleyFlow/shithub/internal/repos/templates" |
| 26 | usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc" | 27 | usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc" |
@@ -164,9 +165,10 @@ func (h *Handlers) renderNewForm(w http.ResponseWriter, r *http.Request, form fo |
| 164 | } | 165 | } |
| 165 | } | 166 | } |
| 166 | | 167 | |
| 167 | -// repoHome serves GET /{owner}/{repo}. For S11 it renders the empty- | 168 | +// repoHome serves GET /{owner}/{repo}. Forks on whether the bare repo |
| 168 | -// repo placeholder when the repo has zero commits; once tree views land | 169 | +// has any branches: empty → quick-setup placeholder; populated → a slim |
| 169 | -// (S17) this path will fork between empty and code-listing. | 170 | +// "post-push" view with the head commit on the default branch. The full |
| | 171 | +// tree/file listing is S17. |
| 170 | func (h *Handlers) repoHome(w http.ResponseWriter, r *http.Request) { | 172 | func (h *Handlers) repoHome(w http.ResponseWriter, r *http.Request) { |
| 171 | owner := chi.URLParam(r, "owner") | 173 | owner := chi.URLParam(r, "owner") |
| 172 | name := chi.URLParam(r, "repo") | 174 | name := chi.URLParam(r, "repo") |
@@ -177,8 +179,17 @@ func (h *Handlers) repoHome(w http.ResponseWriter, r *http.Request) { |
| 177 | return | 179 | return |
| 178 | } | 180 | } |
| 179 | | 181 | |
| 180 | - w.Header().Set("Content-Type", "text/html; charset=utf-8") | 182 | + diskPath, fsErr := h.d.RepoFS.RepoPath(owner, row.Name) |
| 181 | - if err := h.d.Render.Render(w, "repo/empty", map[string]any{ | 183 | + hasBranch := false |
| | 184 | + if fsErr == nil { |
| | 185 | + if ok, herr := repogit.HasAnyBranch(r.Context(), diskPath); herr == nil { |
| | 186 | + hasBranch = ok |
| | 187 | + } else { |
| | 188 | + h.d.Logger.WarnContext(r.Context(), "repo: HasAnyBranch", "error", herr) |
| | 189 | + } |
| | 190 | + } |
| | 191 | + |
| | 192 | + common := map[string]any{ |
| 182 | "Title": row.Name + " · " + owner, | 193 | "Title": row.Name + " · " + owner, |
| 183 | "CSRFToken": middleware.CSRFTokenForRequest(r), | 194 | "CSRFToken": middleware.CSRFTokenForRequest(r), |
| 184 | "Owner": owner, | 195 | "Owner": owner, |
@@ -187,8 +198,27 @@ func (h *Handlers) repoHome(w http.ResponseWriter, r *http.Request) { |
| 187 | "HTTPSCloneURL": h.d.CloneURLs.BaseURL + "/" + owner + "/" + row.Name + ".git", | 198 | "HTTPSCloneURL": h.d.CloneURLs.BaseURL + "/" + owner + "/" + row.Name + ".git", |
| 188 | "SSHEnabled": h.d.CloneURLs.SSHEnabled, | 199 | "SSHEnabled": h.d.CloneURLs.SSHEnabled, |
| 189 | "SSHCloneURL": h.d.CloneURLs.SSHHost + ":" + owner + "/" + row.Name + ".git", | 200 | "SSHCloneURL": h.d.CloneURLs.SSHHost + ":" + owner + "/" + row.Name + ".git", |
| 190 | - }); err != nil { | 201 | + } |
| 191 | - h.d.Logger.ErrorContext(r.Context(), "repo: render empty", "error", err) | 202 | + |
| | 203 | + w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| | 204 | + if !hasBranch { |
| | 205 | + if err := h.d.Render.RenderPage(w, r, "repo/empty", common); err != nil { |
| | 206 | + h.d.Logger.ErrorContext(r.Context(), "repo: render empty", "error", err) |
| | 207 | + } |
| | 208 | + return |
| | 209 | + } |
| | 210 | + |
| | 211 | + // Populated path. Look up the head of the default branch — if missing |
| | 212 | + // (push went to a non-default branch only), fall through to a |
| | 213 | + // branch-not-yet-on-default note. |
| | 214 | + head, found, herr := repogit.HeadOf(r.Context(), diskPath, row.DefaultBranch) |
| | 215 | + if herr != nil { |
| | 216 | + h.d.Logger.WarnContext(r.Context(), "repo: HeadOf", "error", herr) |
| | 217 | + } |
| | 218 | + common["HeadFound"] = found |
| | 219 | + common["Head"] = head |
| | 220 | + if err := h.d.Render.RenderPage(w, r, "repo/populated", common); err != nil { |
| | 221 | + h.d.Logger.ErrorContext(r.Context(), "repo: render populated", "error", err) |
| 192 | } | 222 | } |
| 193 | } | 223 | } |
| 194 | | 224 | |