diff --git a/fetch.go b/fetch.go index 08af2b1..212791f 100644 --- a/fetch.go +++ b/fetch.go @@ -20,7 +20,8 @@ var ( noRecurse bool insecure bool // Allow the use of insecure protocols tests bool - all bool + all bool // Fetch all but .git, .hg and .bzr + all_vcs bool // Fetch all including .git, .hg and .bzr ) func addFetchFlags(fs *flag.FlagSet) { @@ -31,11 +32,13 @@ func addFetchFlags(fs *flag.FlagSet) { 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") + fs.BoolVar(&all_vcs, "A", false, + "fetch all files and subfolders including .git, .hg and .bzr") } var cmdFetch = &Command{ Name: "fetch", - UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t|-a] importpath", + UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] [-t|-a|-A] importpath", Short: "fetch a remote dependency", Long: `fetch vendors an upstream import path. @@ -52,6 +55,8 @@ Flags: fetch also _test.go files and testdata. -a fetch all files and subfolders, ignoring ONLY .git, .hg and .bzr. + -A + fetch all files and subfolders, including .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. @@ -196,6 +201,7 @@ func fetchRecursive(m *vendor.Manifest, fullPath string, level int) error { Path: extra, NoTests: !tests, AllFiles: all, + AllVCS: all_vcs, } if err := m.AddDependency(dep); err != nil { @@ -207,7 +213,7 @@ func fetchRecursive(m *vendor.Manifest, fullPath string, level int) error { dst := filepath.Join(vendorDir, dep.Importpath) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles); err != nil { + if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles, dep.AllVCS); err != nil { return err } @@ -230,7 +236,7 @@ func fetchRecursive(m *vendor.Manifest, fullPath string, level int) error { return fmt.Errorf("unable to derive the root repo import path") } rootRepoPath := strings.TrimRight(strings.TrimSuffix(dep.Importpath, dep.Path), "/") - deps, err := vendor.ParseImports(src, wc.Dir(), rootRepoPath, tests, all) + deps, err := vendor.ParseImports(src, wc.Dir(), rootRepoPath, tests, all, all_vcs) if err != nil { return fmt.Errorf("failed to parse imports: %s", err) } diff --git a/fileutils/fileutils.go b/fileutils/fileutils.go index da0db9e..016d3c5 100644 --- a/fileutils/fileutils.go +++ b/fileutils/fileutils.go @@ -26,7 +26,7 @@ var licenseFiles = []string{ "LICENSE", "LICENCE", "UNLICENSE", "COPYING", "COPYRIGHT", } -func ShouldSkip(path string, info os.FileInfo, tests, all bool) bool { +func ShouldSkip(path string, info os.FileInfo, tests, all bool, all_vcs bool) bool { name := filepath.Base(path) relevantFile := false @@ -46,6 +46,8 @@ func ShouldSkip(path string, info os.FileInfo, tests, all bool) bool { skip := false switch { + case all_vcs: + skip = false case all && !(name == ".git" && info.IsDir()) && name != ".bzr" && name != ".hg": skip = false @@ -75,13 +77,13 @@ func ShouldSkip(path string, info os.FileInfo, tests, all bool) bool { // 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, all bool) error { +func Copypath(dst string, src string, tests, all bool, all_vcs bool) error { err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error { if err != nil { return err } - skip := ShouldSkip(path, info, tests, all) + skip := ShouldSkip(path, info, tests, all, all_vcs) if skip { if info.IsDir() { diff --git a/fileutils/fileutils_test.go b/fileutils/fileutils_test.go index 2be29c8..4c17f4e 100644 --- a/fileutils/fileutils_test.go +++ b/fileutils/fileutils_test.go @@ -15,7 +15,7 @@ func TestCopypathSymlinks(t *testing.T) { dst := mktemp(t) defer RemoveAll(dst) src := filepath.Join("_testdata", "copyfile") - if err := Copypath(dst, src, true, false); err != nil { + if err := Copypath(dst, src, true, false, 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/imports.go b/gbvendor/imports.go index 299bf6e..0c48139 100644 --- a/gbvendor/imports.go +++ b/gbvendor/imports.go @@ -19,7 +19,7 @@ import ( // ParseImports parses Go packages from a specific root returning a set of import paths. // vendorRoot is how deep to go looking for vendor folders, usually the repo root. // vendorPrefix is the vendorRoot import path. -func ParseImports(root, vendorRoot, vendorPrefix string, tests, all bool) (map[string]bool, error) { +func ParseImports(root, vendorRoot, vendorPrefix string, tests, all, all_vcs bool) (map[string]bool, error) { pkgs := make(map[string]bool) var walkFn = func(p string, info os.FileInfo, err error) error { @@ -27,7 +27,7 @@ func ParseImports(root, vendorRoot, vendorPrefix string, tests, all bool) (map[s return err } - if fileutils.ShouldSkip(p, info, tests, all) { + if fileutils.ShouldSkip(p, info, tests, all, all_vcs) { if info.IsDir() { return filepath.SkipDir } diff --git a/gbvendor/manifest.go b/gbvendor/manifest.go index 54f304a..22077b4 100644 --- a/gbvendor/manifest.go +++ b/gbvendor/manifest.go @@ -117,6 +117,9 @@ type Dependency struct { // AllFiles indicates that no files were ignored. AllFiles bool `json:"allfiles,omitempty"` + + // AllVCS indicates that no files were ignored, including .git, .hg and .bzr VCS directories. + AllVCS bool `json:"allvcs,omitempty"` } // WriteManifest writes a Manifest to the path. If the manifest does diff --git a/restore.go b/restore.go index dc0b1e3..78579f6 100644 --- a/restore.go +++ b/restore.go @@ -98,6 +98,9 @@ func downloadDependency(dep vendor.Dependency, errors *uint32, vendorDir string, if dep.AllFiles { extraMsg = "(without file exclusions)" } + if dep.AllVCS { + extraMsg = "(including all files and VCS directories)" + } if recursive { log.Printf("fetching recursive %s %s", dep.Importpath, extraMsg) } else { @@ -123,7 +126,7 @@ func downloadDependency(dep vendor.Dependency, errors *uint32, vendorDir string, } } - if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles); err != nil { + if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles, dep.AllVCS); err != nil { return err } diff --git a/update.go b/update.go index 9c73a49..5209bec 100644 --- a/update.go +++ b/update.go @@ -109,7 +109,7 @@ Flags: dst := filepath.Join(vendorDir, filepath.FromSlash(dep.Importpath)) src := filepath.Join(wc.Dir(), dep.Path) - if err := fileutils.Copypath(dst, src, !d.NoTests, d.AllFiles); err != nil { + if err := fileutils.Copypath(dst, src, !d.NoTests, d.AllFiles, d.AllVCS); err != nil { return err }