6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 16:49:43 +00:00

Skip cloning a repo if target path already exists when getting a dump file

This commit is contained in:
Grzegorz Dlugoszewski
2020-06-30 10:23:10 +02:00
parent 28b24ec5ce
commit 7b9e74f903
2 changed files with 18 additions and 18 deletions

View File

@@ -3,6 +3,7 @@ package pkg
import (
"fmt"
"git-get/pkg/git"
"git-get/pkg/io"
"path"
)
@@ -37,13 +38,13 @@ func cloneSingleRepo(c *GetCfg) error {
return err
}
cloneOpts := &git.CloneOpts{
opts := &git.CloneOpts{
URL: url,
Path: path.Join(c.Root, URLToPath(url)),
Branch: c.Branch,
}
_, err = git.Clone(cloneOpts)
_, err = git.Clone(opts)
return err
}
@@ -60,14 +61,19 @@ func cloneDumpFile(c *GetCfg) error {
return err
}
cloneOpts := &git.CloneOpts{
URL: url,
Path: path.Join(c.Root, URLToPath(url)),
Branch: line.branch,
IgnoreExisting: true,
opts := &git.CloneOpts{
URL: url,
Path: path.Join(c.Root, URLToPath(url)),
Branch: line.branch,
}
_, err = git.Clone(cloneOpts)
// If target path already exists, skip cloning this repo
if exists, _ := io.Exists(opts.Path); exists {
continue
}
fmt.Printf("Cloning %s...\n", opts.URL.String())
_, err = git.Clone(opts)
if err != nil {
return err
}