From 57de1ff991a864c8adf669e3919247c555e7a75a Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Sat, 4 Nov 2017 19:26:38 +0200 Subject: [PATCH] Fix API raw file content access for default branch (#2849) --- integrations/api_repo_raw_test.go | 3 +++ modules/context/repo.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/integrations/api_repo_raw_test.go b/integrations/api_repo_raw_test.go index 045e812210..7ef930ff3f 100644 --- a/integrations/api_repo_raw_test.go +++ b/integrations/api_repo_raw_test.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) 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) } diff --git a/modules/context/repo.go b/modules/context/repo.go index 850b127e59..c61010ecba 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -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: