Skip to content

Commit 0f47c8c

Browse files
committed
fix
1 parent 13dbd26 commit 0f47c8c

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

routers/web/repo/code_frequency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func CodeFrequency(ctx *context.Context) {
2929

3030
// CodeFrequencyData returns JSON of code frequency data
3131
func CodeFrequencyData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
32+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3333
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3434
ctx.Status(http.StatusAccepted)
3535
return

routers/web/repo/contributors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func Contributors(ctx *context.Context) {
2626

2727
// ContributorsData renders JSON of contributors along with their weekly commit statistics
2828
func ContributorsData(ctx *context.Context) {
29-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
29+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3030
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3131
ctx.Status(http.StatusAccepted)
3232
return

routers/web/repo/recent_commits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func RecentCommits(ctx *context.Context) {
2929

3030
// RecentCommitsData returns JSON of recent commits data
3131
func RecentCommitsData(ctx *context.Context) {
32-
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
32+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
3333
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
3434
ctx.Status(http.StatusAccepted)
3535
return

routers/web/repo/search.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,23 @@ func Search(ctx *context.Context) {
6767
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx)
6868
}
6969
} else {
70+
searchRefName := git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch) // BranchName should be default branch or the first existing branch
7071
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
7172
ContextLineNumber: 1,
7273
IsFuzzy: prepareSearch.IsFuzzy,
73-
RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch
74+
RefName: searchRefName.String(),
7475
PathspecList: indexSettingToGitGrepPathspecList(),
7576
})
7677
if err != nil {
7778
// TODO: if no branch exists, it reports: exit status 128, fatal: this operation must be run in a work tree.
7879
ctx.ServerError("GrepSearch", err)
7980
return
8081
}
82+
commitID, err := ctx.Repo.GitRepo.GetRefCommitID(searchRefName.String())
83+
if err != nil {
84+
ctx.ServerError("GrepSearch", err)
85+
return
86+
}
8187
total = len(res)
8288
pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res))
8389
pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res))
@@ -86,7 +92,7 @@ func Search(ctx *context.Context) {
8692
searchResults = append(searchResults, &code_indexer.Result{
8793
RepoID: ctx.Repo.Repository.ID,
8894
Filename: r.Filename,
89-
CommitID: ctx.Repo.CommitID,
95+
CommitID: commitID,
9096
// UpdatedUnix: not supported yet
9197
// Language: not supported yet
9298
// Color: not supported yet

0 commit comments

Comments
 (0)