فهرست منبع

Merge pull request #20 from anant2614/go-git_for_clones

use go-git for cloning
Zachary Rice 8 سال پیش
والد
کامیت
4137d3cfc0
1فایلهای تغییر یافته به همراه7 افزوده شده و 2 حذف شده
  1. 7 2
      leaks.go

+ 7 - 2
leaks.go

@@ -12,6 +12,7 @@ import (
 	"strings"
 	"sync"
 	"syscall"
+	"gopkg.in/src-d/go-git.v4"
 )
 
 // LeakElem contains the line and commit of a leak
@@ -25,14 +26,18 @@ func start(opts *Options) {
 	c := make(chan os.Signal, 2)
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 
+	repoName := getLocalRepoName(opts.RepoURL)
 	fmt.Printf("Cloning \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL)
-	err := exec.Command("git", "clone", opts.RepoURL).Run()
+	_, err := git.PlainClone(appRoot + "/" + repoName, false, &git.CloneOptions{
+		URL:               opts.RepoURL,
+		RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
+	})
 	if err != nil {
+		cleanup(repoName)
 		log.Printf("failed to clone repo %v", err)
 		return
 	}
 	fmt.Printf("Evaluating \x1b[37;1m%s\x1b[0m...\n", opts.RepoURL)
-	repoName := getLocalRepoName(opts.RepoURL)
 	if err = os.Chdir(repoName); err != nil {
 		log.Fatal(err)
 	}