From c628817c22b3c253b5353bc26ff86757dcc74255 Mon Sep 17 00:00:00 2001 From: Grzegorz Dlugoszewski Date: Wed, 27 May 2020 13:02:06 +0200 Subject: [PATCH] Add quiet flag to Clone method --- new/repo.go | 10 ++++++++-- new/repo_test.go | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/new/repo.go b/new/repo.go index e00950f..a56dd1f 100644 --- a/new/repo.go +++ b/new/repo.go @@ -1,6 +1,7 @@ package new import ( + "io" "os" "github.com/go-git/go-git/v5/plumbing/cache" @@ -17,7 +18,12 @@ type Repo struct { Status *RepoStatus } -func CloneRepo(url string, path billy.Filesystem) (r *Repo, err error) { +func CloneRepo(url string, path billy.Filesystem, quiet bool) (r *Repo, err error) { + var output io.Writer + if !quiet { + output = os.Stdout + } + opts := &git.CloneOptions{ URL: url, Auth: nil, @@ -27,7 +33,7 @@ func CloneRepo(url string, path billy.Filesystem) (r *Repo, err error) { NoCheckout: false, Depth: 0, RecurseSubmodules: git.NoRecurseSubmodules, - Progress: os.Stdout, + Progress: output, Tags: git.AllTags, } diff --git a/new/repo_test.go b/new/repo_test.go index c838d2a..7b01833 100644 --- a/new/repo_test.go +++ b/new/repo_test.go @@ -10,7 +10,7 @@ import ( func TestRepoCloneInMemory(t *testing.T) { path := memfs.New() - repo, err := CloneRepo("https://github.com/grdl/dotfiles", path) + repo, err := CloneRepo("https://github.com/grdl/dotfiles", path, true) checkFatal(t, err) wt, err := repo.repo.Worktree() @@ -26,7 +26,7 @@ func TestRepoCloneInMemory(t *testing.T) { func TestRepoCloneOnDisk(t *testing.T) { path := osfs.New(newTempDir(t)) - repo, err := CloneRepo("https://github.com/grdl/dotfiles", path) + repo, err := CloneRepo("https://github.com/grdl/dotfiles", path, true) checkFatal(t, err) wt, err := repo.repo.Worktree()