diff options
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/code_frequency.go | 2 | ||||
-rw-r--r-- | routers/web/repo/contributors.go | 2 | ||||
-rw-r--r-- | routers/web/repo/recent_commits.go | 2 | ||||
-rw-r--r-- | routers/web/repo/search.go | 10 | ||||
-rw-r--r-- | routers/web/repo/setting/webhook.go | 2 |
5 files changed, 13 insertions, 5 deletions
diff --git a/routers/web/repo/code_frequency.go b/routers/web/repo/code_frequency.go index 6572adce74..e212d3b60c 100644 --- a/routers/web/repo/code_frequency.go +++ b/routers/web/repo/code_frequency.go @@ -29,7 +29,7 @@ func CodeFrequency(ctx *context.Context) { // CodeFrequencyData returns JSON of code frequency data func CodeFrequencyData(ctx *context.Context) { - if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil { + if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil { if errors.Is(err, contributors_service.ErrAwaitGeneration) { ctx.Status(http.StatusAccepted) return diff --git a/routers/web/repo/contributors.go b/routers/web/repo/contributors.go index e9c0919955..93dec1f350 100644 --- a/routers/web/repo/contributors.go +++ b/routers/web/repo/contributors.go @@ -26,7 +26,7 @@ func Contributors(ctx *context.Context) { // ContributorsData renders JSON of contributors along with their weekly commit statistics func ContributorsData(ctx *context.Context) { - if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil { + if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil { if errors.Is(err, contributors_service.ErrAwaitGeneration) { ctx.Status(http.StatusAccepted) return diff --git a/routers/web/repo/recent_commits.go b/routers/web/repo/recent_commits.go index dc72081900..228eb0dbac 100644 --- a/routers/web/repo/recent_commits.go +++ b/routers/web/repo/recent_commits.go @@ -29,7 +29,7 @@ func RecentCommits(ctx *context.Context) { // RecentCommitsData returns JSON of recent commits data func RecentCommitsData(ctx *context.Context) { - if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil { + if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil { if errors.Is(err, contributors_service.ErrAwaitGeneration) { ctx.Status(http.StatusAccepted) return diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index d589586dad..bbbe5c1081 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -67,10 +67,11 @@ func Search(ctx *context.Context) { ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx) } } else { + searchRefName := git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch) // BranchName should be default branch or the first existing branch res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{ ContextLineNumber: 1, IsFuzzy: prepareSearch.IsFuzzy, - RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch + RefName: searchRefName.String(), PathspecList: indexSettingToGitGrepPathspecList(), }) if err != nil { @@ -78,6 +79,11 @@ func Search(ctx *context.Context) { ctx.ServerError("GrepSearch", err) return } + commitID, err := ctx.Repo.GitRepo.GetRefCommitID(searchRefName.String()) + if err != nil { + ctx.ServerError("GetRefCommitID", err) + return + } total = len(res) pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res)) pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res)) @@ -86,7 +92,7 @@ func Search(ctx *context.Context) { searchResults = append(searchResults, &code_indexer.Result{ RepoID: ctx.Repo.Repository.ID, Filename: r.Filename, - CommitID: ctx.Repo.CommitID, + CommitID: commitID, // UpdatedUnix: not supported yet // Language: not supported yet // Color: not supported yet diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index 1b0ba83af4..ce67ea3c01 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -654,6 +654,8 @@ func TestWebhook(ctx *context.Context) { } // Grab latest commit or fake one if it's empty repository. + // Note: in old code, the "ctx.Repo.Commit" is the last commit of the default branch. + // New code doesn't set that commit, so it always uses the fake commit to test webhook. commit := ctx.Repo.Commit if commit == nil { ghost := user_model.NewGhostUser() |