From 0fbf761d1930f9336be6da8d17ae6032203a9381 Mon Sep 17 00:00:00 2001 From: Gusted Date: Thu, 4 Jan 2024 23:09:07 +0100 Subject: [PATCH] [GITEA] Handle non-existant commit in Archive request - When a user requests a archive of a non-existant commit `git.ErrNotExist` is returned, but was not gracefully handled resulting in a 500 error. - Doesn't exist in v1.22 due to it being refactored away in cbf923e87bca0f50c2c01a60ccf544b63c365e98 - Adds integration test. --- routers/web/repo/repo.go | 2 +- tests/integration/repo_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 88cbd701d2..36099896bf 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -421,7 +421,7 @@ func Download(ctx *context.Context) { if err != nil { if errors.Is(err, archiver_service.ErrUnknownArchiveFormat{}) { ctx.Error(http.StatusBadRequest, err.Error()) - } else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) { + } else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) || git.IsErrNotExist(err) { ctx.Error(http.StatusNotFound, err.Error()) } else { ctx.ServerError("archiver_service.NewRequest", err) diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 2ac1632188..5d3908eb7e 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -720,3 +720,12 @@ func TestRenamedFileHistory(t *testing.T) { htmlDoc.AssertElement(t, ".ui.bottom.attached.header", false) }) } + +func TestArchiveRequest(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + req := NewRequest(t, "GET", "/user2/repo1/archive/a480fe666d6f550787b6cc85047b966d1f8d6bbf.zip") + session.MakeRequest(t, req, http.StatusNotFound) +}