Skip to content
This repository was archived by the owner on Aug 25, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.

Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -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)
}
Expand Down
8 changes: 5 additions & 3 deletions fileutils/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion fileutils/fileutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions gbvendor/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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 {
if err != nil {
return err
}

if fileutils.ShouldSkip(p, info, tests, all) {
if fileutils.ShouldSkip(p, info, tests, all, all_vcs) {
if info.IsDir() {
return filepath.SkipDir
}
Expand Down
3 changes: 3 additions & 0 deletions gbvendor/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down