Author | Jakob Wakeling <[email protected]> |
Date | 2023-10-05 04:51:04 |
Commit | b227a682d64aaa71bb456ebe8fdea60bd52acdbc |
Parent | 6fb9830bd1c4a268ef12cc400d946e08260f1dcf |
Fix 404 error when editing repo with no commits
Diffstat
M | src/repo/edit.go | | | 21 | ++++++++++----------- |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/repo/edit.go b/src/repo/edit.go index 53af807..3ae2ab0 100644 --- a/src/repo/edit.go +++ b/src/repo/edit.go @@ -64,26 +64,25 @@ func HandleEdit(w http.ResponseWriter, r *http.Request) { gr, err := git.PlainOpen(goit.RepoPath(repo.Name)) if err != nil { - log.Println("[/repo/file]", err.Error()) + log.Println("[/repo/edit]", err.Error()) goit.HttpError(w, http.StatusInternalServerError) return } ref, err := gr.Head() - if errors.Is(err, plumbing.ErrReferenceNotFound) { - goit.HttpError(w, http.StatusNotFound) - return - } else if err != nil { - log.Println("[/repo/file]", err.Error()) + if err != nil && !errors.Is(err, plumbing.ErrReferenceNotFound) { + log.Println("[/repo/edit]", err.Error()) goit.HttpError(w, http.StatusInternalServerError) return } - if readme, _ := findReadme(gr, ref); readme != "" { - data.Readme = path.Join("/", repo.Name, "file", readme) - } - if licence, _ := findLicence(gr, ref); licence != "" { - data.Licence = path.Join("/", repo.Name, "file", licence) + if ref != nil { + if readme, _ := findReadme(gr, ref); readme != "" { + data.Readme = path.Join("/", repo.Name, "file", readme) + } + if licence, _ := findLicence(gr, ref); licence != "" { + data.Licence = path.Join("/", repo.Name, "file", licence) + } } if r.Method == http.MethodPost {