6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 17:24:49 +00:00
Files
git-get/pkg/get.go
Grzegorz Dlugoszewski 3e9c7644c6 Rename bundle to dump
2020-06-18 15:47:15 +02:00

59 lines
882 B
Go

package pkg
import (
"git-get/pkg/repo"
"path"
)
// GetCfg provides configuration for the Get command.
type GetCfg struct {
Branch string
Dump string
Root string
URL string
}
// Get executes the "git get" command.
func Get(c *GetCfg) error {
if c.Dump != "" {
return cloneDumpFile(c)
}
if c.URL != "" {
return cloneSingleRepo(c)
}
return nil
}
func cloneSingleRepo(c *GetCfg) error {
url, err := ParseURL(c.URL)
if err != nil {
return err
}
cloneOpts := &repo.CloneOpts{
URL: url,
Path: path.Join(c.Root, URLToPath(url)),
Branch: c.Branch,
}
_, err = repo.Clone(cloneOpts)
return err
}
func cloneDumpFile(c *GetCfg) error {
opts, err := ParseDumpFile(c.Dump)
if err != nil {
return err
}
for _, opt := range opts {
path := path.Join(c.Root, URLToPath(opt.URL))
opt.Path = path
_, _ = repo.Clone(opt)
}
return nil
}