From 914a428f8409ad17a50e95857cf2da00a2540be5 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Mon, 15 May 2017 17:43:23 +0200 Subject: [PATCH] Allow partial restore for vendoring a different fork --- README.md | 2 +- restore.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ed280b..dab9f71 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ vendor it at the original import path. Since this is not a common use-case, there's no support in `gvt fetch` for it, however, you can manually edit the `vendor/manifest` file, changing `repository` -and `revision`, and then run `gvt restore`. +and `revision`, and then run `gvt restore --filter=github.com/MyOrg/MyVendoredLib`. `gvt update` will stay on your fork. diff --git a/restore.go b/restore.go index dc0b1e3..48d7817 100644 --- a/restore.go +++ b/restore.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "strings" "sync" "sync/atomic" @@ -14,13 +15,15 @@ import ( ) var ( - rbInsecure bool // Allow the use of insecure protocols - rbConnections uint // Count of concurrent download connections + rbInsecure bool // Allow the use of insecure protocols + rbConnections uint // Count of concurrent download connections + rbFilter string // Only restore this package or subpackages ) func addRestoreFlags(fs *flag.FlagSet) { fs.BoolVar(&rbInsecure, "precaire", false, "allow the use of insecure protocols") fs.UintVar(&rbConnections, "connections", 8, "count of parallel download connections") + fs.StringVar(&rbFilter, "filter", "", "only restore this package or subpackages") } var cmdRestore = &Command{ @@ -78,7 +81,9 @@ func restore(manFile string) error { } for _, dep := range m.Dependencies { - depC <- dep + if rbFilter == "" || rbFilter == dep.Importpath || strings.HasPrefix(dep.Importpath, rbFilter+"/") { + depC <- dep + } } close(depC) wg.Wait()