diff --git a/cmd/gb-vendor/fetch.go b/cmd/gb-vendor/fetch.go index c112fc0..0a46c99 100644 --- a/cmd/gb-vendor/fetch.go +++ b/cmd/gb-vendor/fetch.go @@ -31,6 +31,7 @@ var ( recurse bool // should we fetch recursively insecure bool // Allow the use of insecure protocols + clone bool // allows to fetch as a full git repo ) func addFetchFlags(fs *flag.FlagSet) { @@ -39,11 +40,12 @@ func addFetchFlags(fs *flag.FlagSet) { fs.StringVar(&tag, "tag", "", "tag of the package") fs.BoolVar(&noRecurse, "no-recurse", false, "do not fetch recursively") fs.BoolVar(&insecure, "precaire", false, "allow the use of insecure protocols") + fs.BoolVar(&clone, "clone", false, "fetch repository with .git folder") } var cmdFetch = &cmd.Command{ Name: "fetch", - UsageLine: "fetch [-branch branch | -revision rev | -tag tag] [-precaire] [-no-recurse] importpath", + UsageLine: "fetch [-branch branch | -revision rev | -tag tag] [-clone] [-precaire] [-no-recurse] importpath", Short: "fetch a remote dependency", Long: `fetch vendors an upstream import path. @@ -54,6 +56,8 @@ Flags: -branch branch fetch from the name branch. If not supplied the default upstream branch will be used. + -clone + fetches as a full git repository -no-recurse do not fetch recursively. -tag tag @@ -73,7 +77,7 @@ Flags: case 1: path := args[0] recurse = !noRecurse - return fetch(ctx, path, recurse) + return fetch(ctx, path, recurse, clone) default: return errors.New("more than one import path supplied") } @@ -81,7 +85,7 @@ Flags: AddFlags: addFetchFlags, } -func fetch(ctx *gb.Context, path string, recurse bool) error { +func fetch(ctx *gb.Context, path string, recurse bool, clone bool) error { m, err := vendor.ReadManifest(manifestFile(ctx)) if err != nil { return errors.Wrap(err, "could not load manifest") @@ -122,6 +126,7 @@ func fetch(ctx *gb.Context, path string, recurse bool) error { Revision: rev, Branch: b, Path: extra, + Clone: clone, } if err := m.AddDependency(dep); err != nil { @@ -131,7 +136,7 @@ func fetch(ctx *gb.Context, path string, recurse bool) error { dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src); err != nil { + if err := fileutils.Copypath(dst, src, clone); err != nil { return err } @@ -192,7 +197,7 @@ func fetch(ctx *gb.Context, path string, recurse bool) error { sort.Strings(keys) pkg := keys[0] fmt.Println("fetching recursive dependency", pkg) - if err := fetch(ctx, pkg, false); err != nil { + if err := fetch(ctx, pkg, false, false); err != nil { return err } } diff --git a/cmd/gb-vendor/restore.go b/cmd/gb-vendor/restore.go index 08d69a4..c309284 100644 --- a/cmd/gb-vendor/restore.go +++ b/cmd/gb-vendor/restore.go @@ -61,7 +61,7 @@ func restore(ctx *gb.Context) error { dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src); err != nil { + if err := fileutils.Copypath(dst, src, dep.Clone); err != nil { errChan <- err return } diff --git a/cmd/gb-vendor/update.go b/cmd/gb-vendor/update.go index f50dd9c..fde0c36 100644 --- a/cmd/gb-vendor/update.go +++ b/cmd/gb-vendor/update.go @@ -111,7 +111,7 @@ Flags: dst := filepath.Join(ctx.Projectdir(), "vendor", "src", filepath.FromSlash(dep.Importpath)) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src); err != nil { + if err := fileutils.Copypath(dst, src, dep.Clone); err != nil { return err } diff --git a/internal/fileutils/fileutils.go b/internal/fileutils/fileutils.go index 63a730b..4bc4d17 100644 --- a/internal/fileutils/fileutils.go +++ b/internal/fileutils/fileutils.go @@ -17,13 +17,15 @@ const debugCopyfile = false // Copypath copies the contents of src to dst, excluding any file or // directory that starts with a period. -func Copypath(dst string, src string) error { +func Copypath(dst string, src string, withGit bool) error { err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { if err != nil { return err } - if strings.HasPrefix(filepath.Base(path), ".") { + git := filepath.Base(path) == ".git" && withGit + + if strings.HasPrefix(filepath.Base(path), ".") && !git { if info.IsDir() { return filepath.SkipDir } diff --git a/internal/fileutils/fileutils_test.go b/internal/fileutils/fileutils_test.go index cfc40a2..61530b5 100644 --- a/internal/fileutils/fileutils_test.go +++ b/internal/fileutils/fileutils_test.go @@ -14,7 +14,7 @@ func TestCopypathSkipsSymlinks(t *testing.T) { dst := mktemp(t) defer RemoveAll(dst) src := filepath.Join("_testdata", "copyfile", "a") - if err := Copypath(dst, src); err != nil { + if err := Copypath(dst, src, false); err != nil { t.Fatalf("copypath(%s, %s): %v", dst, src, err) } } diff --git a/internal/vendor/manifest.go b/internal/vendor/manifest.go index f11e114..af3c07b 100644 --- a/internal/vendor/manifest.go +++ b/internal/vendor/manifest.go @@ -83,6 +83,9 @@ type Dependency struct { // Path is the path inside the Repository where the // dependency was fetched from. Path string `json:"path,omitempty"` + + // Clone describes was repository cloned as a full git repository. + Clone bool `json:"clone,omitempty"` } // WriteManifest writes a Manifest to the path. If the manifest does