Goit

Simple and lightweight Git web server
Mirror of https://github.com/Jamozed/Goit
git clone http://git.omkov.net/Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2023-07-18 12:58:41
Commit25ea845fd12009e041cf228fe3225ef0c27f15f7
Parent8abd3436c0a348d9a084e4a83a16e028ca2e8199

Omit empty tables for commits, branches, and tags

Diffstat

M res/repo_log.html | 40 ++++++++++++++++++++++------------------
M res/repo_refs.html | 72 ++++++++++++++++++++++++++++++++++++++----------------------------------
M res/style.css | 2 +-
M src/repo.go | 8 +++++---

4 files changed, 66 insertions, 56 deletions

diff --git a/res/repo_log.html b/res/repo_log.html
index 113d825..8483e0b 100644
--- a/res/repo_log.html
+++ b/res/repo_log.html
@@ -25,22 +25,26 @@
 			</td>
 		</tr>
 	</table><hr>
-	<table>
-		<thead>
-			<tr>
-				<td><b>Date</b></td>
-				<td><b>Message</b></td>
-				<td><b>Author</b></td>
-			</tr>
-		</thead>
-		<tbody>
-		{{range .Commits}}
-			<tr>
-				<td>{{.Date}}</a></td>
-				<td>{{.Message}}</td>
-				<td>{{.Author}}</td>
-			</tr>
-		{{end}}
-		</tbody>
-	</table>
+	{{if .Commits}}
+		<table>
+			<thead>
+				<tr>
+					<td><b>Date</b></td>
+					<td><b>Message</b></td>
+					<td><b>Author</b></td>
+				</tr>
+			</thead>
+			<tbody>
+			{{range .Commits}}
+				<tr>
+					<td>{{.Date}}</a></td>
+					<td>{{.Message}}</td>
+					<td>{{.Author}}</td>
+				</tr>
+			{{end}}
+			</tbody>
+		</table>
+	{{else}}
+		<span>No commits</span>
+	{{end}}
 </body>
diff --git a/res/repo_refs.html b/res/repo_refs.html
index 19fc5d3..9fc5f00 100644
--- a/res/repo_refs.html
+++ b/res/repo_refs.html
@@ -25,38 +25,42 @@
 			</td>
 		</tr>
 	</table><hr>
-	<h2>Branches</h2>
-	<table>
-		<thead>
-			<tr>
-				<td><b>Name</b></td>
-				<td><b>Hash</b></td>
-			</tr>
-		</thead>
-		<tbody>
-		{{range .Branches}}
-			<tr>
-				<td>{{.Name}}</a></td>
-				<td>{{.Hash}}</td>
-			</tr>
-		{{end}}
-		</tbody>
-	</table>
-	<h2>Tags</h2>
-	<table>
-		<thead>
-			<tr>
-				<td><b>Name</b></td>
-				<td><b>Hash</b></td>
-			</tr>
-		</thead>
-		<tbody>
-		{{range .Tags}}
-			<tr>
-				<td>{{.Name}}</a></td>
-				<td>{{.Hash}}</td>
-			</tr>
-		{{end}}
-		</tbody>
-	</table>
+	{{if .Branches}}
+		<h2>Branches</h2>
+		<table>
+			<thead>
+				<tr>
+					<td><b>Name</b></td>
+					<td><b>Hash</b></td>
+				</tr>
+			</thead>
+			<tbody>
+			{{range .Branches}}
+				<tr>
+					<td>{{.Name}}</a></td>
+					<td>{{.Hash}}</td>
+				</tr>
+			{{end}}
+			</tbody>
+		</table>
+	{{end}}
+	{{if .Tags}}
+		<h2>Tags</h2>
+		<table>
+			<thead>
+				<tr>
+					<td><b>Name</b></td>
+					<td><b>Hash</b></td>
+				</tr>
+			</thead>
+			<tbody>
+			{{range .Tags}}
+				<tr>
+					<td>{{.Name}}</a></td>
+					<td>{{.Hash}}</td>
+				</tr>
+			{{end}}
+			</tbody>
+		</table>
+	{{end}}
 </body>
diff --git a/res/style.css b/res/style.css
index 28108ed..efd7049 100644
--- a/res/style.css
+++ b/res/style.css
@@ -3,7 +3,7 @@ body { font-family: monospace; margin: 1em; }
 
 a { color: #FF7E00; text-decoration: none; }
 a:hover { text-decoration: underline; }
-h1 { font-size: 1em; margin: 0; }
+h1, h2 { font-size: 1em; margin: 0; }
 hr { border: 0; height: 1em; margin: 0; }
 
 table td { padding: 0 0.4em; }
diff --git a/src/repo.go b/src/repo.go
index 01a6fca..ec35f3f 100644
--- a/src/repo.go
+++ b/src/repo.go
@@ -126,9 +126,11 @@ func (g *Goit) HandleRepoLog(w http.ResponseWriter, r *http.Request) {
 		HttpError(w, http.StatusInternalServerError)
 		return
 	} else if ref, err := gr.Head(); err != nil {
-		log.Println("[Repo:Log]", err.Error())
-		HttpError(w, http.StatusInternalServerError)
-		return
+		if !errors.Is(err, plumbing.ErrReferenceNotFound) {
+			log.Println("[Repo:Log]", err.Error())
+			HttpError(w, http.StatusInternalServerError)
+			return
+		}
 	} else if iter, err := gr.Log(&git.LogOptions{From: ref.Hash()}); err != nil {
 		log.Println("[Repo:Log]", err.Error())
 		HttpError(w, http.StatusInternalServerError)