Skip to content

Commit 5852974

Browse files
committed
Use rev-parse to check if commit exists
Signed-off-by: Gary Kim <[email protected]>
1 parent 582a180 commit 5852974

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

modules/markup/html.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@ func fullSha1PatternProcessor(ctx *postProcessCtx, node *html.Node) {
647647
// sha1CurrentPatternProcessor renders SHA1 strings to corresponding links that
648648
// are assumed to be in the same repository.
649649
func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) {
650+
if ctx.metas == nil || ctx.metas["user"] == "" || ctx.metas["repo"] == "" || ctx.metas["repoPath"] == "" {
651+
return
652+
}
650653
m := sha1CurrentPattern.FindStringSubmatchIndex(node.Data)
651654
if m == nil {
652655
return
@@ -660,11 +663,8 @@ func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) {
660663
// as used by git and github for linking and thus we have to do similar.
661664
// Because of this, we check to make sure that a matched hash is actually
662665
// a commit in the repository before making it a link.
663-
if ctx.metas["repoPath"] != "" {
664-
repo, err := git.OpenRepository(ctx.metas["repoPath"])
665-
if err != nil || !repo.IsCommitExist(hash) {
666-
return
667-
}
666+
if _, err := git.NewCommand("rev-parse", "--verify", hash).RunInDirBytes(ctx.metas["repoPath"]); err != nil {
667+
return
668668
}
669669

670670
replaceContent(node, m[2], m[3],

0 commit comments

Comments
 (0)