fix: remove template file from generated repo (#11691)

This PR fixes a bug where the previously-implemented functionality to delete the `.gitea/template` or `.forgejo/template` file when generating a repository from a template was not working. The issue happened because the code was using `util.Remove()` with a relative path, but this resolves against the process working directory instead of the temporary clone directory. The fix was to use `root.Remove()` which is based on an `os.OpenRoot()` anchored at `tmpDir`.

Updated integration tests and verified that they pass with this change and fail without it.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11691
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Brandon Rothweiler <bdr9@noreply.codeberg.org>
Co-committed-by: Brandon Rothweiler <bdr9@noreply.codeberg.org>
This commit is contained in:
Brandon Rothweiler 2026-03-17 23:39:10 +01:00 committed by Gusted
parent 9a741f7bd5
commit c987e8e3ce
3 changed files with 30 additions and 16 deletions

View file

@ -120,6 +120,10 @@ Clone URL: %s%s/%s.git`,
req = NewRequestf(t, "GET", "/%s/%s/raw/branch/master/%s.log", generateOwner.Name, generateRepoName, generateRepoName)
resp = session.MakeRequest(t, req, http.StatusOK)
assert.Equal(t, generateRepoName, resp.Body.String())
// The .gitea/template file should not be present in the generated repo
req = NewRequestf(t, "GET", "/%s/%s/raw/branch/master/.gitea/template", generateOwner.Name, generateRepoName)
session.MakeRequest(t, req, http.StatusNotFound)
}
// test form elements before and after POST error response
@ -291,6 +295,16 @@ func TestRepoGenerateTemplating(t *testing.T) {
user.Name,
generatedName)
assert.Equal(t, body, resp.Body.String())
// The .forgejo/template file should not be present in the generated repo
req = NewRequestf(
t,
"GET", "/%s/%s/raw/branch/%s/.forgejo/template",
user.Name,
generatedName,
template.DefaultBranch,
)
session.MakeRequest(t, req, http.StatusNotFound)
})
}