mirror of
https://github.com/grdl/git-get.git
synced 2026-02-12 16:25:14 +00:00
Skip cloning a repo if target path already exists when getting a dump file
This commit is contained in:
22
pkg/get.go
22
pkg/get.go
@@ -3,6 +3,7 @@ package pkg
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git-get/pkg/git"
|
"git-get/pkg/git"
|
||||||
|
"git-get/pkg/io"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,13 +38,13 @@ func cloneSingleRepo(c *GetCfg) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneOpts := &git.CloneOpts{
|
opts := &git.CloneOpts{
|
||||||
URL: url,
|
URL: url,
|
||||||
Path: path.Join(c.Root, URLToPath(url)),
|
Path: path.Join(c.Root, URLToPath(url)),
|
||||||
Branch: c.Branch,
|
Branch: c.Branch,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = git.Clone(cloneOpts)
|
_, err = git.Clone(opts)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -60,14 +61,19 @@ func cloneDumpFile(c *GetCfg) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneOpts := &git.CloneOpts{
|
opts := &git.CloneOpts{
|
||||||
URL: url,
|
URL: url,
|
||||||
Path: path.Join(c.Root, URLToPath(url)),
|
Path: path.Join(c.Root, URLToPath(url)),
|
||||||
Branch: line.branch,
|
Branch: line.branch,
|
||||||
IgnoreExisting: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ type repo struct {
|
|||||||
|
|
||||||
// CloneOpts specify detail about repository to clone.
|
// CloneOpts specify detail about repository to clone.
|
||||||
type CloneOpts struct {
|
type CloneOpts struct {
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
Path string // TODO: should Path be a part of clone opts?
|
Path string // TODO: should Path be a part of clone opts?
|
||||||
Branch string
|
Branch string
|
||||||
Quiet bool
|
Quiet bool
|
||||||
IgnoreExisting bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open checks if given path can be accessed and returns a Repo instance pointing to it.
|
// Open checks if given path can be accessed and returns a Repo instance pointing to it.
|
||||||
@@ -56,11 +55,6 @@ func Open(path string) (Repo, error) {
|
|||||||
|
|
||||||
// Clone clones repository specified with CloneOpts.
|
// Clone clones repository specified with CloneOpts.
|
||||||
func Clone(opts *CloneOpts) (Repo, error) {
|
func Clone(opts *CloneOpts) (Repo, error) {
|
||||||
// TODO: not sure if this check should be here
|
|
||||||
if opts.IgnoreExisting {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
runGit := run.Git("clone", opts.URL.String(), opts.Path)
|
runGit := run.Git("clone", opts.URL.String(), opts.Path)
|
||||||
if opts.Branch != "" {
|
if opts.Branch != "" {
|
||||||
runGit = run.Git("clone", "--branch", opts.Branch, "--single-branch", opts.URL.String(), opts.Path)
|
runGit = run.Git("clone", "--branch", opts.Branch, "--single-branch", opts.URL.String(), opts.Path)
|
||||||
|
|||||||
Reference in New Issue
Block a user