@@ -67,17 +67,23 @@ func Search(ctx *context.Context) {
67
67
ctx .Data ["CodeIndexerUnavailable" ] = ! code_indexer .IsAvailable (ctx )
68
68
}
69
69
} else {
70
+ searchRefName := git .RefNameFromBranch (ctx .Repo .Repository .DefaultBranch ) // BranchName should be default branch or the first existing branch
70
71
res , err := git .GrepSearch (ctx , ctx .Repo .GitRepo , prepareSearch .Keyword , git.GrepOptions {
71
72
ContextLineNumber : 1 ,
72
73
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 (),
74
75
PathspecList : indexSettingToGitGrepPathspecList (),
75
76
})
76
77
if err != nil {
77
78
// TODO: if no branch exists, it reports: exit status 128, fatal: this operation must be run in a work tree.
78
79
ctx .ServerError ("GrepSearch" , err )
79
80
return
80
81
}
82
+ commitID , err := ctx .Repo .GitRepo .GetRefCommitID (searchRefName .String ())
83
+ if err != nil {
84
+ ctx .ServerError ("GrepSearch" , err )
85
+ return
86
+ }
81
87
total = len (res )
82
88
pageStart := min ((page - 1 )* setting .UI .RepoSearchPagingNum , len (res ))
83
89
pageEnd := min (page * setting .UI .RepoSearchPagingNum , len (res ))
@@ -86,7 +92,7 @@ func Search(ctx *context.Context) {
86
92
searchResults = append (searchResults , & code_indexer.Result {
87
93
RepoID : ctx .Repo .Repository .ID ,
88
94
Filename : r .Filename ,
89
- CommitID : ctx . Repo . CommitID ,
95
+ CommitID : commitID ,
90
96
// UpdatedUnix: not supported yet
91
97
// Language: not supported yet
92
98
// Color: not supported yet
0 commit comments