From a97046592db08e62952360cc08659f9367b51d71 Mon Sep 17 00:00:00 2001 From: ashish Date: Thu, 28 Oct 2021 19:03:03 +0530 Subject: [PATCH] Handled potential panic in one of the cases in gitwalker Signed-off-by: ashish --- utils/walker/git.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/utils/walker/git.go b/utils/walker/git.go index e42f935c..29933916 100644 --- a/utils/walker/git.go +++ b/utils/walker/git.go @@ -134,14 +134,18 @@ func clonewalk(g *Git) error { path := filepath.Join(os.TempDir(), g.repo, strconv.FormatInt(time.Now().UTC().UnixNano(), 10)) defer os.RemoveAll(path) - logs := os.Stdout - if !g.showLogs { - logs = nil + var err error + if g.showLogs { + _, err = git.PlainClone(path, false, &git.CloneOptions{ + URL: fmt.Sprintf("%s/%s/%s", g.baseURL, g.owner, g.repo), + Progress: os.Stdout, + }) + } else { + _, err = git.PlainClone(path, false, &git.CloneOptions{ + URL: fmt.Sprintf("%s/%s/%s", g.baseURL, g.owner, g.repo), + }) } - _, err := git.PlainClone(path, false, &git.CloneOptions{ - URL: fmt.Sprintf("%s/%s/%s", g.baseURL, g.owner, g.repo), - Progress: logs, - }) + if err != nil { return ErrCloningRepo(err) } @@ -192,7 +196,9 @@ func clonewalk(g *Git) error { return nil } err := g.readFile(f, path) - fmt.Println(err.Error()) + if err != nil { + fmt.Println(err.Error()) + } } return nil