Fix API raw file content access for default branch (#2849)

tokarchuk/v1.17
Lauris BH 7 years ago committed by GitHub
parent 76b8c3c68f
commit 57de1ff991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      integrations/api_repo_raw_test.go
  2. 6
      modules/context/repo.go

@ -25,4 +25,7 @@ func TestAPIReposRaw(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/%s/README.md", user.Name, ref) req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/%s/README.md", user.Name, ref)
session.MakeRequest(t, req, http.StatusOK) session.MakeRequest(t, req, http.StatusOK)
} }
// Test default branch
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/README.md", user.Name)
session.MakeRequest(t, req, http.StatusOK)
} }

@ -507,7 +507,11 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
if refName := getRefName(ctx, RepoRefTag); len(refName) > 0 { if refName := getRefName(ctx, RepoRefTag); len(refName) > 0 {
return refName return refName
} }
return getRefName(ctx, RepoRefCommit) if refName := getRefName(ctx, RepoRefCommit); len(refName) > 0 {
return refName
}
ctx.Repo.TreePath = path
return ctx.Repo.Repository.DefaultBranch
case RepoRefBranch: case RepoRefBranch:
return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsBranchExist) return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsBranchExist)
case RepoRefTag: case RepoRefTag:

Loading…
Cancel
Save