all: add NoTests mode, default on, toggled off by 'fetch -t' Existing manifest files will have NoTests: false, so their 'gvt restore' behavior won't change, but the default 'gvt fetch' behavior changed to excluding tests, and can be overridden with '-t'. Closes #21
diff --git a/alldocs.go b/alldocs.go index 293e44b..656ba9d 100644 --- a/alldocs.go +++ b/alldocs.go
@@ -21,7 +21,7 @@ Fetch a remote dependency Usage: - gvt fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] importpath + gvt fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t] importpath fetch vendors an upstream import path. @@ -29,6 +29,8 @@ from private repositories that cannot be probed. Flags: + -t + fetch also _test.go files and testdata. -branch branch fetch from the named branch. Will also be used by gvt update. If not supplied the default upstream branch will be used.
diff --git a/fetch.go b/fetch.go index 434274e..cf8bb2c 100644 --- a/fetch.go +++ b/fetch.go
@@ -20,6 +20,7 @@ tag string noRecurse bool insecure bool // Allow the use of insecure protocols + tests bool recurse bool // should we fetch recursively ) @@ -30,11 +31,12 @@ 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(&tests, "t", false, "fetch _test.go files and testdata") } var cmdFetch = &Command{ Name: "fetch", - UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] importpath", + UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t] importpath", Short: "fetch a remote dependency", Long: `fetch vendors an upstream import path. @@ -42,6 +44,8 @@ from private repositories that cannot be probed. Flags: + -t + fetch also _test.go files and testdata. -branch branch fetch from the named branch. Will also be used by gvt update. If not supplied the default upstream branch will be used. @@ -112,6 +116,7 @@ Revision: rev, Branch: branch, Path: extra, + NoTests: !tests, } if err := m.AddDependency(dep); err != nil { @@ -121,7 +126,7 @@ dst := filepath.Join(vendorDir(), dep.Importpath) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src, true); err != nil { + if err := fileutils.Copypath(dst, src, !dep.NoTests); err != nil { return err }
diff --git a/gbvendor/manifest.go b/gbvendor/manifest.go index f4d973e..397208f 100644 --- a/gbvendor/manifest.go +++ b/gbvendor/manifest.go
@@ -82,6 +82,10 @@ // Path is the path inside the Repository where the // dependency was fetched from. Path string `json:"path,omitempty"` + + // NoTests indicates that test files were ignored. + // In the negative for backwards compatibility. + NoTests bool `json:"notests,omitempty"` } // WriteManifest writes a Manifest to the path. If the manifest does
diff --git a/restore.go b/restore.go index 81d338d..d2a3309 100644 --- a/restore.go +++ b/restore.go
@@ -91,10 +91,14 @@ } func downloadDependency(dep vendor.Dependency, errors *uint32, vendorDir string, recursive bool) error { + testsMsg := "" + if !dep.NoTests { + testsMsg = "(including tests)" + } if recursive { - log.Printf("fetching recursive %s", dep.Importpath) + log.Printf("fetching recursive %s %s", dep.Importpath, testsMsg) } else { - log.Printf("fetching %s", dep.Importpath) + log.Printf("fetching %s %s", dep.Importpath, testsMsg) } repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure) @@ -116,7 +120,7 @@ } } - if err := fileutils.Copypath(dst, src, true); err != nil { + if err := fileutils.Copypath(dst, src, !dep.NoTests); err != nil { return err }
diff --git a/update.go b/update.go index e1f261d..1fe48a5 100644 --- a/update.go +++ b/update.go
@@ -96,6 +96,7 @@ Revision: rev, Branch: branch, Path: extra, + NoTests: d.NoTests, } if err := fileutils.RemoveAll(filepath.Join(vendorDir(), filepath.FromSlash(d.Importpath))); err != nil { @@ -106,7 +107,7 @@ dst := filepath.Join(vendorDir(), filepath.FromSlash(dep.Importpath)) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src, true); err != nil { + if err := fileutils.Copypath(dst, src, !d.NoTests); err != nil { return err }