diff --git a/pkg/repo.go b/pkg/repo.go index eb24ee3..0575b14 100644 --- a/pkg/repo.go +++ b/pkg/repo.go @@ -1,6 +1,9 @@ package pkg import ( + "os" + "path" + "github.com/pkg/errors" git "github.com/libgit2/git2go/v30" @@ -76,3 +79,13 @@ func (r *Repo) Fetch() error { return nil } + +func MakeDir(repoRoot, repoPath string) (string, error) { + dir := path.Join(repoRoot, repoPath) + err := os.MkdirAll(dir, 0775) + if err != nil { + return "", errors.Wrap(err, "Failed creating repo directory") + } + + return dir, nil +} diff --git a/pkg/repo_test.go b/pkg/repo_test.go index 2749882..f7374fb 100644 --- a/pkg/repo_test.go +++ b/pkg/repo_test.go @@ -1,6 +1,9 @@ package pkg -import "testing" +import ( + "os" + "testing" +) func TestFetch(t *testing.T) { // Create origin repo with a single commit in master @@ -43,3 +46,18 @@ func TestFetch(t *testing.T) { t.Errorf("Master should not be ahead") } } + +func TestMakeDir(t *testing.T) { + repoRoot := newTempDir(t) + repoPath := "github.com/grdl/git-get" + + dir, err := MakeDir(repoRoot, repoPath) + checkFatal(t, err) + + stat, err := os.Stat(dir) + checkFatal(t, err) + + if !stat.IsDir() { + t.Errorf("Path is not a directory: %s", dir) + } +}