Add -a option and allfiles manifest entry to include all files Closes #30
diff --git a/README.md b/README.md index 5b5071d..4c6cbe6 100644 --- a/README.md +++ b/README.md
@@ -51,7 +51,7 @@ Files and folders starting with `.` or `_` are ignored. Only [files relevant to the Go compiler](https://golang.org/cmd/go/#hdr-File_types) are fetched. LICENSE files are always included, too. -Test files and `testdata` folders can be included with `-t`. +Test files and `testdata` folders can be included with `-t`. To include all files (except the repository metadata), use `-a`. ``` $ tree -d
diff --git a/alldocs.go b/alldocs.go index 656ba9d..f6727ea 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] [-t] importpath + gvt fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t|-a] importpath fetch vendors an upstream import path. @@ -31,6 +31,8 @@ Flags: -t fetch also _test.go files and testdata. + -a + fetch all files and subfolders, ignoring ONLY .git, .hg and .bzr. -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 b21f3b4..ae43ee9 100644 --- a/fetch.go +++ b/fetch.go
@@ -21,6 +21,7 @@ noRecurse bool insecure bool // Allow the use of insecure protocols tests bool + all bool recurse bool // should we fetch recursively ) @@ -32,11 +33,12 @@ 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") + fs.BoolVar(&all, "a", false, "fetch all files and subfolders") } var cmdFetch = &Command{ Name: "fetch", - UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t] importpath", + UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t|-a] importpath", Short: "fetch a remote dependency", Long: `fetch vendors an upstream import path. @@ -46,6 +48,8 @@ Flags: -t fetch also _test.go files and testdata. + -a + fetch all files and subfolders, ignoring ONLY .git, .hg and .bzr. -branch branch fetch from the named branch. Will also be used by gvt update. If not supplied the default upstream branch will be used. @@ -117,6 +121,7 @@ Branch: b, Path: extra, NoTests: !tests, + AllFiles: all, } if err := m.AddDependency(dep); err != nil { @@ -126,7 +131,7 @@ dst := filepath.Join(vendorDir(), dep.Importpath) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src, !dep.NoTests); err != nil { + if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles); err != nil { return err }
diff --git a/fileutils/fileutils.go b/fileutils/fileutils.go index 2a36a1d..5584de7 100644 --- a/fileutils/fileutils.go +++ b/fileutils/fileutils.go
@@ -28,7 +28,7 @@ // Copypath copies the contents of src to dst, excluding any file that is not // relevant to the Go compiler. -func Copypath(dst string, src string, tests bool) error { +func Copypath(dst string, src string, tests, all bool) error { err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -53,6 +53,9 @@ skip := false switch { + case all && !(name == ".git" && info.IsDir()) && name != ".bzr" && name != ".hg": + skip = false + // Include all files in a testdata folder case tests && testdata: skip = false
diff --git a/fileutils/fileutils_test.go b/fileutils/fileutils_test.go index 69bb60a..2be29c8 100644 --- a/fileutils/fileutils_test.go +++ b/fileutils/fileutils_test.go
@@ -15,7 +15,7 @@ dst := mktemp(t) defer RemoveAll(dst) src := filepath.Join("_testdata", "copyfile") - if err := Copypath(dst, src, true); err != nil { + if err := Copypath(dst, src, true, false); err != nil { t.Fatalf("copypath(%s, %s): %v", dst, src, err) } res, err := os.Readlink(filepath.Join(dst, "a", "rick"))
diff --git a/gbvendor/manifest.go b/gbvendor/manifest.go index 397208f..2282cde 100644 --- a/gbvendor/manifest.go +++ b/gbvendor/manifest.go
@@ -86,6 +86,9 @@ // NoTests indicates that test files were ignored. // In the negative for backwards compatibility. NoTests bool `json:"notests,omitempty"` + + // AllFiles indicates that no files were ignored. + AllFiles bool `json:"allfiles,omitempty"` } // WriteManifest writes a Manifest to the path. If the manifest does
diff --git a/restore.go b/restore.go index dfd078a..c0756fd 100644 --- a/restore.go +++ b/restore.go
@@ -91,14 +91,17 @@ } func downloadDependency(dep vendor.Dependency, errors *uint32, vendorDir string, recursive bool) error { - testsMsg := "" + extraMsg := "" if !dep.NoTests { - testsMsg = "(including tests)" + extraMsg = "(including tests)" + } + if dep.AllFiles { + extraMsg = "(without file exclusions)" } if recursive { - log.Printf("fetching recursive %s %s", dep.Importpath, testsMsg) + log.Printf("fetching recursive %s %s", dep.Importpath, extraMsg) } else { - log.Printf("fetching %s %s", dep.Importpath, testsMsg) + log.Printf("fetching %s %s", dep.Importpath, extraMsg) } repo, _, err := vendor.DeduceRemoteRepo(dep.Importpath, rbInsecure) @@ -120,7 +123,7 @@ } } - if err := fileutils.Copypath(dst, src, !dep.NoTests); err != nil { + if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles); err != nil { return err }
diff --git a/update.go b/update.go index f7d38d6..8d71ae6 100644 --- a/update.go +++ b/update.go
@@ -107,7 +107,7 @@ dst := filepath.Join(vendorDir(), filepath.FromSlash(dep.Importpath)) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src, !d.NoTests); err != nil { + if err := fileutils.Copypath(dst, src, !d.NoTests, d.AllFiles); err != nil { return err }