mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 13:45:19 +00:00
Merge pull request '[BUG] Allow 4 charachter SHA in /src/commit
' (#4828) from gusted/forgejo-short-sha into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4828 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
14850847ee
|
@ -903,7 +903,7 @@ func getRefName(ctx *Base, repo *Repository, pathType RepoRefType) string {
|
||||||
case RepoRefCommit:
|
case RepoRefCommit:
|
||||||
parts := strings.Split(path, "/")
|
parts := strings.Split(path, "/")
|
||||||
|
|
||||||
if len(parts) > 0 && len(parts[0]) >= 7 && len(parts[0]) <= repo.GetObjectFormat().FullLength() {
|
if len(parts) > 0 && len(parts[0]) >= 4 && len(parts[0]) <= repo.GetObjectFormat().FullLength() {
|
||||||
repo.TreePath = strings.Join(parts[1:], "/")
|
repo.TreePath = strings.Join(parts[1:], "/")
|
||||||
return parts[0]
|
return parts[0]
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1027,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
|
||||||
return cancel
|
return cancel
|
||||||
}
|
}
|
||||||
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
|
||||||
} else if len(refName) >= 7 && len(refName) <= ctx.Repo.GetObjectFormat().FullLength() {
|
} else if len(refName) >= 4 && len(refName) <= ctx.Repo.GetObjectFormat().FullLength() {
|
||||||
ctx.Repo.IsViewCommit = true
|
ctx.Repo.IsViewCommit = true
|
||||||
ctx.Repo.CommitID = refName
|
ctx.Repo.CommitID = refName
|
||||||
|
|
||||||
|
|
|
@ -710,6 +710,13 @@ func TestCommitView(t *testing.T) {
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
commitTitle := doc.Find(".commit-summary").Text()
|
commitTitle := doc.Find(".commit-summary").Text()
|
||||||
assert.Contains(t, commitTitle, "Initial commit")
|
assert.Contains(t, commitTitle, "Initial commit")
|
||||||
|
|
||||||
|
req = NewRequest(t, "GET", "/user2/repo1/src/commit/65f1")
|
||||||
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
doc = NewHTMLParser(t, resp.Body)
|
||||||
|
commitTitle = doc.Find(".shortsha").Text()
|
||||||
|
assert.Contains(t, commitTitle, "65f1bf27bc")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Full commit ID", func(t *testing.T) {
|
t.Run("Full commit ID", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue