]> source.dussan.org Git - gitea.git/commitdiff
Fix API raw file content access for default branch (#2849)
authorLauris BH <lauris@nix.lv>
Sat, 4 Nov 2017 17:26:38 +0000 (19:26 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Nov 2017 17:26:38 +0000 (19:26 +0200)
integrations/api_repo_raw_test.go
modules/context/repo.go

index 045e8122106ec355f879691c24f30288940d9e95..7ef930ff3f6493c2d6f9cb2e67cd6a544b5edc7e 100644 (file)
@@ -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)
                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)
 }
index 850b127e595ae8fde772004aa35044874c04eb6f..c61010ecbad243a057cafdcafcaa110af0d82b66 100644 (file)
@@ -507,7 +507,11 @@ func getRefName(ctx *Context, pathType RepoRefType) string {
                if refName := getRefName(ctx, RepoRefTag); len(refName) > 0 {
                        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:
                return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsBranchExist)
        case RepoRefTag: