mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-12 04:54:56 +00:00
Use rev-parse to check if commit exists
Signed-off-by: Gary Kim <gary@garykim.dev>
This commit is contained in:
parent
582a180621
commit
5852974137
|
@ -647,6 +647,9 @@ func fullSha1PatternProcessor(ctx *postProcessCtx, node *html.Node) {
|
||||||
// sha1CurrentPatternProcessor renders SHA1 strings to corresponding links that
|
// sha1CurrentPatternProcessor renders SHA1 strings to corresponding links that
|
||||||
// are assumed to be in the same repository.
|
// are assumed to be in the same repository.
|
||||||
func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) {
|
func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) {
|
||||||
|
if ctx.metas == nil || ctx.metas["user"] == "" || ctx.metas["repo"] == "" || ctx.metas["repoPath"] == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
m := sha1CurrentPattern.FindStringSubmatchIndex(node.Data)
|
m := sha1CurrentPattern.FindStringSubmatchIndex(node.Data)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return
|
return
|
||||||
|
@ -660,11 +663,8 @@ func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) {
|
||||||
// as used by git and github for linking and thus we have to do similar.
|
// as used by git and github for linking and thus we have to do similar.
|
||||||
// Because of this, we check to make sure that a matched hash is actually
|
// Because of this, we check to make sure that a matched hash is actually
|
||||||
// a commit in the repository before making it a link.
|
// a commit in the repository before making it a link.
|
||||||
if ctx.metas["repoPath"] != "" {
|
if _, err := git.NewCommand("rev-parse", "--verify", hash).RunInDirBytes(ctx.metas["repoPath"]); err != nil {
|
||||||
repo, err := git.OpenRepository(ctx.metas["repoPath"])
|
return
|
||||||
if err != nil || !repo.IsCommitExist(hash) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceContent(node, m[2], m[3],
|
replaceContent(node, m[2], m[3],
|
||||||
|
|
Loading…
Reference in a new issue