Skip to content
Snippets Groups Projects
Commit 37360710 authored by Tamer Tas's avatar Tamer Tas
Browse files

pkg/cmd/download: use `git clone` instead of manual zip downloads

Enables
- Private repositories
- Repositories using different version control systems
parent 3bf80d99
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/tmrts/boilr/pkg/cmd/util" "github.com/tmrts/boilr/pkg/cmd/util"
"github.com/tmrts/boilr/pkg/host" "github.com/tmrts/boilr/pkg/host"
"github.com/tmrts/boilr/pkg/util/exit" "github.com/tmrts/boilr/pkg/util/exit"
"github.com/tmrts/boilr/pkg/util/git"
"github.com/tmrts/boilr/pkg/util/osutil" "github.com/tmrts/boilr/pkg/util/osutil"
"github.com/tmrts/boilr/pkg/util/tlog" "github.com/tmrts/boilr/pkg/util/tlog"
"github.com/tmrts/boilr/pkg/util/validate" "github.com/tmrts/boilr/pkg/util/validate"
...@@ -122,21 +123,21 @@ var Download = &cli.Command{ ...@@ -122,21 +123,21 @@ var Download = &cli.Command{
if shouldOverwrite := GetBoolFlag(c, "force"); !shouldOverwrite { if shouldOverwrite := GetBoolFlag(c, "force"); !shouldOverwrite {
exit.OK("Template %v already exists use -f to overwrite the template", templateName) exit.OK("Template %v already exists use -f to overwrite the template", templateName)
} }
case !exists:
if err := os.MkdirAll(targetDir, 0755); err != nil { // TODO(tmrts): extract `template delete` helper and use that one
if err := os.RemoveAll(targetDir); err != nil {
exit.Error(fmt.Errorf("download: %s", err)) exit.Error(fmt.Errorf("download: %s", err))
} }
} }
zipURL := host.ZipURL(templateURL) // TODO(tmrts): allow fetching other branches than 'master'
if err := git.Clone(targetDir, git.CloneOptions{
if err := downloadZip(zipURL, targetDir); err != nil { URL: host.URL(templateURL),
// Delete if download transaction fails }); err != nil {
defer os.RemoveAll(targetDir)
exit.Error(fmt.Errorf("download: %s", err)) exit.Error(fmt.Errorf("download: %s", err))
} }
// TODO(tmrts): use git-notes as metadata storage or boltdb
if err := serializeMetadata(templateName, templateURL, targetDir); err != nil { if err := serializeMetadata(templateName, templateURL, targetDir); err != nil {
exit.Error(fmt.Errorf("download: %s", err)) exit.Error(fmt.Errorf("download: %s", err))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment