From bcb9f4c75677e49e23ef7bf3075d1cd4f86a698c Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 16 Mar 2016 21:41:06 -0400 Subject: [PATCH 1/5] Add ability to remove nested vendor and Godeps/_workspace directories --- action/get.go | 7 ++++++- action/install.go | 9 +++++++-- action/update.go | 7 ++++++- glide.go | 29 ++++++++++++++++++++++++++--- path/strip.go | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 7 deletions(-) diff --git a/action/get.go b/action/get.go index e27030b3..e0fe9ad9 100644 --- a/action/get.go +++ b/action/get.go @@ -15,7 +15,7 @@ import ( // Get fetches one or more dependencies and installs. // // This includes resolving dependency resolution and re-generating the lock file. -func Get(names []string, installer *repo.Installer, insecure, skipRecursive, strip bool) { +func Get(names []string, installer *repo.Installer, insecure, skipRecursive, strip, stripVendor bool) { base := gpath.Basepath() EnsureGopath() EnsureVendorDir() @@ -84,6 +84,11 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str msg.Info("Removing version control data from vendor directory...") gpath.StripVcs() } + + if stripVendor { + msg.Info("Removing nested vendor and Godeps/_workspace directories...") + gpath.StripVendor() + } } func writeLock(conf, confcopy *cfg.Config, base string) { diff --git a/action/install.go b/action/install.go index bed37440..5349962a 100644 --- a/action/install.go +++ b/action/install.go @@ -12,7 +12,7 @@ import ( ) // Install installs a vendor directory based on an existing Glide configuration. -func Install(installer *repo.Installer, strip bool) { +func Install(installer *repo.Installer, strip, stripVendor bool) { base := "." // Ensure GOPATH EnsureGopath() @@ -22,7 +22,7 @@ func Install(installer *repo.Installer, strip bool) { // Lockfile exists if !gpath.HasLock(base) { msg.Info("Lock file (glide.lock) does not exist. Performing update.") - Update(installer, false, strip) + Update(installer, false, strip, stripVendor) return } // Load lockfile @@ -63,6 +63,11 @@ func Install(installer *repo.Installer, strip bool) { msg.Info("Removing version control data from vendor directory...") gpath.StripVcs() } + + if stripVendor { + msg.Info("Removing nested vendor and Godeps/_workspace directories...") + gpath.StripVendor() + } } // LoadLockfile loads the contents of a glide.lock file. diff --git a/action/update.go b/action/update.go index cf87b288..451392fd 100644 --- a/action/update.go +++ b/action/update.go @@ -11,7 +11,7 @@ import ( ) // Update updates repos and the lock file from the main glide yaml. -func Update(installer *repo.Installer, skipRecursive, strip bool) { +func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) { base := "." EnsureGopath() EnsureVendorDir() @@ -94,4 +94,9 @@ func Update(installer *repo.Installer, skipRecursive, strip bool) { msg.Info("Removing version control data from vendor directory...") gpath.StripVcs() } + + if stripVendor { + msg.Info("Removing nested vendor and Godeps/_workspace directories...") + gpath.StripVendor() + } } diff --git a/glide.go b/glide.go index 23c47458..486b813b 100644 --- a/glide.go +++ b/glide.go @@ -211,8 +211,16 @@ func commands() []cli.Command { Name: "strip-vcs, s", Usage: "Removes version control metada (e.g, .git directory) from the vendor folder.", }, + cli.BoolFlag{ + Name: "strip-vendor, v", + Usage: "Removes nested vendor and Godeps/_workspace directories. Requires --strip-vcs.", + }, }, Action: func(c *cli.Context) { + if c.Bool("strip-vendor") && !c.Bool("strip-vcs") { + msg.Die("--strip-vendor cannot be used without --strip-vcs") + } + if len(c.Args()) < 1 { fmt.Println("Oops! Package name is required.") os.Exit(1) @@ -232,7 +240,7 @@ func commands() []cli.Command { inst.ResolveAllFiles = c.Bool("all-dependencies") packages := []string(c.Args()) insecure := c.Bool("insecure") - action.Get(packages, inst, insecure, c.Bool("no-recursive"), c.Bool("strip-vcs")) + action.Get(packages, inst, insecure, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor")) }, }, { @@ -412,8 +420,16 @@ Example: Name: "strip-vcs, s", Usage: "Removes version control metada (e.g, .git directory) from the vendor folder.", }, + cli.BoolFlag{ + Name: "strip-vendor, v", + Usage: "Removes nested vendor and Godeps/_workspace directories. Requires --strip-vcs.", + }, }, Action: func(c *cli.Context) { + if c.Bool("strip-vendor") && !c.Bool("strip-vcs") { + msg.Die("--strip-vendor cannot be used without --strip-vcs") + } + installer := repo.NewInstaller() installer.Force = c.Bool("force") installer.UseCache = c.Bool("cache") @@ -423,7 +439,7 @@ Example: installer.Home = gpath.Home() installer.DeleteUnused = c.Bool("deleteOptIn") - action.Install(installer, c.Bool("strip-vcs")) + action.Install(installer, c.Bool("strip-vcs"), c.Bool("strip-vendor")) }, }, { @@ -500,8 +516,15 @@ Example: Name: "strip-vcs, s", Usage: "Removes version control metada (e.g, .git directory) from the vendor folder.", }, + cli.BoolFlag{ + Name: "strip-vendor, v", + Usage: "Removes nested vendor and Godeps/_workspace directories. Requires --strip-vcs.", + }, }, Action: func(c *cli.Context) { + if c.Bool("strip-vendor") && !c.Bool("strip-vcs") { + msg.Die("--strip-vendor cannot be used without --strip-vcs") + } if c.Bool("resolve-current") { util.ResolveCurrent = true @@ -518,7 +541,7 @@ Example: installer.Home = gpath.Home() installer.DeleteUnused = c.Bool("deleteOptIn") - action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vcs")) + action.Update(installer, c.Bool("no-recursive"), c.Bool("strip-vcs"), c.Bool("strip-vendor")) }, }, { diff --git a/path/strip.go b/path/strip.go index e7abe29d..a3705b25 100644 --- a/path/strip.go +++ b/path/strip.go @@ -36,3 +36,39 @@ func stripHandler(path string, info os.FileInfo, err error) error { } return nil } + +// StripVendor removes nested vendor and Godeps/_workspace/ directories. +func StripVendor() error { + if _, err := os.Stat(VendorDir); err != nil { + if os.IsNotExist(err) { + msg.Debug("Vendor directory does not exist.") + } + + return err + } + + return filepath.Walk(VendorDir, stripVendorHandler) +} + +func stripVendorHandler(path string, info os.FileInfo, err error) error { + // Skip the base vendor directory + if path == VendorDir { + return nil + } + + name := info.Name() + p := filepath.Dir(path) + pn := filepath.Base(p) + if name == "vendor" || (name == "_workspace" && pn == "Godeps") { + if _, err := os.Stat(path); err == nil { + if info.IsDir() { + msg.Info("Removing: %s", path) + return os.RemoveAll(path) + } + + msg.Debug("%s is not a directory. Skipping removal", path) + return nil + } + } + return nil +} From b77e14e574f4a3c88636687a97bc71dcce3d9319 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Thu, 17 Mar 2016 13:23:17 -0400 Subject: [PATCH 2/5] Un-rewriting the Godeps import rewrites --- action/get.go | 9 ++- action/install.go | 5 +- action/update.go | 10 ++- godep/godep.go | 27 +++++++++ path/strip.go | 147 ++++++++++++++++++++++++++++++++++++++++++++- path/strip_test.go | 14 +++++ 6 files changed, 207 insertions(+), 5 deletions(-) diff --git a/action/get.go b/action/get.go index e0fe9ad9..e5135e82 100644 --- a/action/get.go +++ b/action/get.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Masterminds/glide/cfg" + "github.com/Masterminds/glide/godep" "github.com/Masterminds/glide/msg" gpath "github.com/Masterminds/glide/path" "github.com/Masterminds/glide/repo" @@ -75,6 +76,9 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str } if !skipRecursive { // Write lock + if stripVendor { + confcopy = godep.RemoveGodepSubpackages(confcopy) + } writeLock(conf, confcopy, base) } else { msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated") @@ -87,7 +91,10 @@ func Get(names []string, installer *repo.Installer, insecure, skipRecursive, str if stripVendor { msg.Info("Removing nested vendor and Godeps/_workspace directories...") - gpath.StripVendor() + err := gpath.StripVendor() + if err != nil { + msg.Err("Unable to strip vendor directories: %s", err) + } } } diff --git a/action/install.go b/action/install.go index 5349962a..3ae39c00 100644 --- a/action/install.go +++ b/action/install.go @@ -66,7 +66,10 @@ func Install(installer *repo.Installer, strip, stripVendor bool) { if stripVendor { msg.Info("Removing nested vendor and Godeps/_workspace directories...") - gpath.StripVendor() + err := gpath.StripVendor() + if err != nil { + msg.Err("Unable to strip vendor directories: %s", err) + } } } diff --git a/action/update.go b/action/update.go index 451392fd..4b0da7b7 100644 --- a/action/update.go +++ b/action/update.go @@ -5,6 +5,7 @@ import ( "github.com/Masterminds/glide/cfg" "github.com/Masterminds/glide/dependency" + "github.com/Masterminds/glide/godep" "github.com/Masterminds/glide/msg" gpath "github.com/Masterminds/glide/path" "github.com/Masterminds/glide/repo" @@ -73,6 +74,10 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) { // from the project. A removed dependency should warn and an added dependency // should be added to the glide.yaml file. See issue #193. + if stripVendor { + confcopy = godep.RemoveGodepSubpackages(confcopy) + } + if !skipRecursive { // Write lock hash, err := conf.Hash() @@ -97,6 +102,9 @@ func Update(installer *repo.Installer, skipRecursive, strip, stripVendor bool) { if stripVendor { msg.Info("Removing nested vendor and Godeps/_workspace directories...") - gpath.StripVendor() + err := gpath.StripVendor() + if err != nil { + msg.Err("Unable to strip vendor directories: %s", err) + } } } diff --git a/godep/godep.go b/godep/godep.go index aad445b8..a7d0525b 100644 --- a/godep/godep.go +++ b/godep/godep.go @@ -7,6 +7,7 @@ import ( "encoding/json" "os" "path/filepath" + "strings" "github.com/Masterminds/glide/cfg" "github.com/Masterminds/glide/msg" @@ -96,3 +97,29 @@ func Parse(dir string) ([]*cfg.Dependency, error) { return buf, nil } + +// RemoveGodepSubpackages strips subpackages from a cfg.Config dependencies that +// contain "Godeps/_workspace/src" as part of the path. +func RemoveGodepSubpackages(c *cfg.Config) *cfg.Config { + for _, d := range c.Imports { + n := []string{} + for _, v := range d.Subpackages { + if !strings.HasPrefix(v, "Godeps/_workspace/src") { + n = append(n, v) + } + } + d.Subpackages = n + } + + for _, d := range c.DevImports { + n := []string{} + for _, v := range d.Subpackages { + if !strings.HasPrefix(v, "Godeps/_workspace/src") { + n = append(n, v) + } + } + d.Subpackages = n + } + + return c +} diff --git a/path/strip.go b/path/strip.go index a3705b25..6f8698d2 100644 --- a/path/strip.go +++ b/path/strip.go @@ -1,8 +1,15 @@ package path import ( + "bytes" + "go/ast" + "go/parser" + "go/printer" + "go/token" "os" "path/filepath" + "strconv" + "strings" "github.com/Masterminds/glide/msg" ) @@ -47,7 +54,12 @@ func StripVendor() error { return err } - return filepath.Walk(VendorDir, stripVendorHandler) + err := filepath.Walk(VendorDir, stripVendorHandler) + if err != nil { + return err + } + + return StripGodepWorkspace() } func stripVendorHandler(path string, info os.FileInfo, err error) error { @@ -56,12 +68,68 @@ func stripVendorHandler(path string, info os.FileInfo, err error) error { return nil } + name := info.Name() + if name == "vendor" { + if _, err := os.Stat(path); err == nil { + if info.IsDir() { + msg.Info("Removing: %s", path) + return os.RemoveAll(path) + } + + msg.Debug("%s is not a directory. Skipping removal", path) + return nil + } + } + return nil +} + +var godepMark = map[string]bool{} + +// StripGodepWorkspace removes any Godeps/_workspace directories and makes sure +// any rewrites are undone. +// Note, this is not concuccency safe. +func StripGodepWorkspace() error { + if _, err := os.Stat(VendorDir); err != nil { + if os.IsNotExist(err) { + msg.Debug("Vendor directory does not exist.") + } + + return err + } + + err := filepath.Walk(VendorDir, stripGodepWorkspaceHandler) + if err != nil { + return err + } + + // Walk the marked projects to make sure rewrites are undone. + for k := range godepMark { + msg.Info("Removing Godep rewrites for %s", k) + err := filepath.Walk(k, rewriteGodepfilesHandler) + if err != nil { + return err + } + } + + return nil +} + +func stripGodepWorkspaceHandler(path string, info os.FileInfo, err error) error { + // Skip the base vendor directory + if path == VendorDir { + return nil + } + name := info.Name() p := filepath.Dir(path) pn := filepath.Base(p) - if name == "vendor" || (name == "_workspace" && pn == "Godeps") { + if name == "_workspace" && pn == "Godeps" { if _, err := os.Stat(path); err == nil { if info.IsDir() { + // Marking this location to make sure rewrites are undone. + pp := filepath.Dir(p) + godepMark[pp] = true + msg.Info("Removing: %s", path) return os.RemoveAll(path) } @@ -72,3 +140,78 @@ func stripVendorHandler(path string, info os.FileInfo, err error) error { } return nil } + +func rewriteGodepfilesHandler(path string, info os.FileInfo, err error) error { + name := info.Name() + if name == "testdata" || name == "vendor" { + return filepath.SkipDir + } + + if info.IsDir() { + return nil + } + + if e := filepath.Ext(path); e != ".go" { + return nil + } + + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, path, nil, parser.ParseComments) + if err != nil { + return err + } + + var changed bool + for _, s := range f.Imports { + n, err := strconv.Unquote(s.Path.Value) + if err != nil { + return err + } + q := rewriteGodepImport(n) + if q != name { + s.Path.Value = strconv.Quote(q) + changed = true + } + } + if !changed { + return nil + } + + printerConfig := &printer.Config{Mode: printer.TabIndent | printer.UseSpaces, Tabwidth: 8} + var buffer bytes.Buffer + if err = printerConfig.Fprint(&buffer, fset, f); err != nil { + return err + } + fset = token.NewFileSet() + f, err = parser.ParseFile(fset, name, &buffer, parser.ParseComments) + ast.SortImports(fset, f) + tpath := path + ".temp" + t, err := os.Create(tpath) + if err != nil { + return err + } + if err = printerConfig.Fprint(t, fset, f); err != nil { + return err + } + if err = t.Close(); err != nil { + return err + } + + msg.Debug("Rewriting Godep imports for %s", path) + + // This is required before the rename on windows. + if err = os.Remove(path); err != nil { + return err + } + return os.Rename(tpath, path) +} + +func rewriteGodepImport(n string) string { + if !strings.Contains(n, "Godeps/_workspace/src") { + return n + } + + i := strings.LastIndex(n, "Godeps/_workspace/src") + + return strings.TrimPrefix(n[i:], "Godeps/_workspace/src/") +} diff --git a/path/strip_test.go b/path/strip_test.go index 6c111944..eb0789c2 100644 --- a/path/strip_test.go +++ b/path/strip_test.go @@ -65,3 +65,17 @@ func TestStripVcs(t *testing.T) { t.Error(".svn directory not deleted") } } + +func TestRewriteGodepImport(t *testing.T) { + tests := map[string]string{ + "github.com/Masterminds/glide/action": "github.com/Masterminds/glide/action", + "github.com/tools/godep/Godeps/_workspace/src/github.com/kr/fs": "github.com/kr/fs", + } + + for k, v := range tests { + o := rewriteGodepImport(k) + if o != v { + t.Errorf("Incorrect Godep import path rewritten %s: %s", v, o) + } + } +} From 9fd0b6739dbf127fad7eb3e99dc16dfc3d913104 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 21 Mar 2016 21:08:43 -0400 Subject: [PATCH 3/5] Moved the godep strip functionality to a custom package --- godep/strip/strip.go | 156 ++++++++++++++++++++++++++++++++++++++ godep/strip/strip_test.go | 17 +++++ path/strip.go | 145 +---------------------------------- path/strip_test.go | 14 ---- 4 files changed, 177 insertions(+), 155 deletions(-) create mode 100644 godep/strip/strip.go create mode 100644 godep/strip/strip_test.go diff --git a/godep/strip/strip.go b/godep/strip/strip.go new file mode 100644 index 00000000..e70d6078 --- /dev/null +++ b/godep/strip/strip.go @@ -0,0 +1,156 @@ +// Package strip removes Godeps/_workspace and undoes the Godep rewrites. This +// essentially removes the old style (pre-vendor) Godep vendoring. +// +// Note, this functionality is deprecated. Once more projects use the Godep +// support for the core vendoring this will no longer be needed. +package strip + +import ( + "bytes" + "go/ast" + "go/parser" + "go/printer" + "go/token" + "os" + "path/filepath" + "strconv" + "strings" + + "github.com/Masterminds/glide/msg" +) + +var godepMark = map[string]bool{} + +var vPath = "vendor" + +// GodepWorkspace removes any Godeps/_workspace directories and makes sure +// any rewrites are undone. +// Note, this is not concuccency safe. +func GodepWorkspace(v string) error { + vPath = v + if _, err := os.Stat(vPath); err != nil { + if os.IsNotExist(err) { + msg.Debug("Vendor directory does not exist.") + } + + return err + } + + err := filepath.Walk(vPath, stripGodepWorkspaceHandler) + if err != nil { + return err + } + + // Walk the marked projects to make sure rewrites are undone. + for k := range godepMark { + msg.Info("Removing Godep rewrites for %s", k) + err := filepath.Walk(k, rewriteGodepfilesHandler) + if err != nil { + return err + } + } + + return nil +} + +func stripGodepWorkspaceHandler(path string, info os.FileInfo, err error) error { + // Skip the base vendor directory + if path == vPath { + return nil + } + + name := info.Name() + p := filepath.Dir(path) + pn := filepath.Base(p) + if name == "_workspace" && pn == "Godeps" { + if _, err := os.Stat(path); err == nil { + if info.IsDir() { + // Marking this location to make sure rewrites are undone. + pp := filepath.Dir(p) + godepMark[pp] = true + + msg.Info("Removing: %s", path) + return os.RemoveAll(path) + } + + msg.Debug("%s is not a directory. Skipping removal", path) + return nil + } + } + return nil +} + +func rewriteGodepfilesHandler(path string, info os.FileInfo, err error) error { + name := info.Name() + if name == "testdata" || name == "vendor" { + return filepath.SkipDir + } + + if info.IsDir() { + return nil + } + + if e := filepath.Ext(path); e != ".go" { + return nil + } + + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, path, nil, parser.ParseComments) + if err != nil { + return err + } + + var changed bool + for _, s := range f.Imports { + n, err := strconv.Unquote(s.Path.Value) + if err != nil { + return err + } + q := rewriteGodepImport(n) + if q != name { + s.Path.Value = strconv.Quote(q) + changed = true + } + } + if !changed { + return nil + } + + printerConfig := &printer.Config{Mode: printer.TabIndent | printer.UseSpaces, Tabwidth: 8} + var buffer bytes.Buffer + if err = printerConfig.Fprint(&buffer, fset, f); err != nil { + return err + } + fset = token.NewFileSet() + f, err = parser.ParseFile(fset, name, &buffer, parser.ParseComments) + ast.SortImports(fset, f) + tpath := path + ".temp" + t, err := os.Create(tpath) + if err != nil { + return err + } + if err = printerConfig.Fprint(t, fset, f); err != nil { + return err + } + if err = t.Close(); err != nil { + return err + } + + msg.Debug("Rewriting Godep imports for %s", path) + + // This is required before the rename on windows. + if err = os.Remove(path); err != nil { + return err + } + return os.Rename(tpath, path) +} + +func rewriteGodepImport(n string) string { + if !strings.Contains(n, "Godeps/_workspace/src") { + return n + } + + i := strings.LastIndex(n, "Godeps/_workspace/src") + + return strings.TrimPrefix(n[i:], "Godeps/_workspace/src/") +} diff --git a/godep/strip/strip_test.go b/godep/strip/strip_test.go new file mode 100644 index 00000000..e260a30a --- /dev/null +++ b/godep/strip/strip_test.go @@ -0,0 +1,17 @@ +package strip + +import "testing" + +func TestRewriteGodepImport(t *testing.T) { + tests := map[string]string{ + "github.com/Masterminds/glide/action": "github.com/Masterminds/glide/action", + "github.com/tools/godep/Godeps/_workspace/src/github.com/kr/fs": "github.com/kr/fs", + } + + for k, v := range tests { + o := rewriteGodepImport(k) + if o != v { + t.Errorf("Incorrect Godep import path rewritten %s: %s", v, o) + } + } +} diff --git a/path/strip.go b/path/strip.go index 6f8698d2..1162f389 100644 --- a/path/strip.go +++ b/path/strip.go @@ -1,16 +1,10 @@ package path import ( - "bytes" - "go/ast" - "go/parser" - "go/printer" - "go/token" "os" "path/filepath" - "strconv" - "strings" + "github.com/Masterminds/glide/godep/strip" "github.com/Masterminds/glide/msg" ) @@ -59,7 +53,9 @@ func StripVendor() error { return err } - return StripGodepWorkspace() + err = strip.GodepWorkspace(VendorDir) + + return err } func stripVendorHandler(path string, info os.FileInfo, err error) error { @@ -82,136 +78,3 @@ func stripVendorHandler(path string, info os.FileInfo, err error) error { } return nil } - -var godepMark = map[string]bool{} - -// StripGodepWorkspace removes any Godeps/_workspace directories and makes sure -// any rewrites are undone. -// Note, this is not concuccency safe. -func StripGodepWorkspace() error { - if _, err := os.Stat(VendorDir); err != nil { - if os.IsNotExist(err) { - msg.Debug("Vendor directory does not exist.") - } - - return err - } - - err := filepath.Walk(VendorDir, stripGodepWorkspaceHandler) - if err != nil { - return err - } - - // Walk the marked projects to make sure rewrites are undone. - for k := range godepMark { - msg.Info("Removing Godep rewrites for %s", k) - err := filepath.Walk(k, rewriteGodepfilesHandler) - if err != nil { - return err - } - } - - return nil -} - -func stripGodepWorkspaceHandler(path string, info os.FileInfo, err error) error { - // Skip the base vendor directory - if path == VendorDir { - return nil - } - - name := info.Name() - p := filepath.Dir(path) - pn := filepath.Base(p) - if name == "_workspace" && pn == "Godeps" { - if _, err := os.Stat(path); err == nil { - if info.IsDir() { - // Marking this location to make sure rewrites are undone. - pp := filepath.Dir(p) - godepMark[pp] = true - - msg.Info("Removing: %s", path) - return os.RemoveAll(path) - } - - msg.Debug("%s is not a directory. Skipping removal", path) - return nil - } - } - return nil -} - -func rewriteGodepfilesHandler(path string, info os.FileInfo, err error) error { - name := info.Name() - if name == "testdata" || name == "vendor" { - return filepath.SkipDir - } - - if info.IsDir() { - return nil - } - - if e := filepath.Ext(path); e != ".go" { - return nil - } - - fset := token.NewFileSet() - f, err := parser.ParseFile(fset, path, nil, parser.ParseComments) - if err != nil { - return err - } - - var changed bool - for _, s := range f.Imports { - n, err := strconv.Unquote(s.Path.Value) - if err != nil { - return err - } - q := rewriteGodepImport(n) - if q != name { - s.Path.Value = strconv.Quote(q) - changed = true - } - } - if !changed { - return nil - } - - printerConfig := &printer.Config{Mode: printer.TabIndent | printer.UseSpaces, Tabwidth: 8} - var buffer bytes.Buffer - if err = printerConfig.Fprint(&buffer, fset, f); err != nil { - return err - } - fset = token.NewFileSet() - f, err = parser.ParseFile(fset, name, &buffer, parser.ParseComments) - ast.SortImports(fset, f) - tpath := path + ".temp" - t, err := os.Create(tpath) - if err != nil { - return err - } - if err = printerConfig.Fprint(t, fset, f); err != nil { - return err - } - if err = t.Close(); err != nil { - return err - } - - msg.Debug("Rewriting Godep imports for %s", path) - - // This is required before the rename on windows. - if err = os.Remove(path); err != nil { - return err - } - return os.Rename(tpath, path) -} - -func rewriteGodepImport(n string) string { - if !strings.Contains(n, "Godeps/_workspace/src") { - return n - } - - i := strings.LastIndex(n, "Godeps/_workspace/src") - - return strings.TrimPrefix(n[i:], "Godeps/_workspace/src/") -} diff --git a/path/strip_test.go b/path/strip_test.go index eb0789c2..6c111944 100644 --- a/path/strip_test.go +++ b/path/strip_test.go @@ -65,17 +65,3 @@ func TestStripVcs(t *testing.T) { t.Error(".svn directory not deleted") } } - -func TestRewriteGodepImport(t *testing.T) { - tests := map[string]string{ - "github.com/Masterminds/glide/action": "github.com/Masterminds/glide/action", - "github.com/tools/godep/Godeps/_workspace/src/github.com/kr/fs": "github.com/kr/fs", - } - - for k, v := range tests { - o := rewriteGodepImport(k) - if o != v { - t.Errorf("Incorrect Godep import path rewritten %s: %s", v, o) - } - } -} From ae402ab287823cdef6b90c4edd9c44a87b45b75c Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 21 Mar 2016 21:26:42 -0400 Subject: [PATCH 4/5] Updating the help docs --- glide.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/glide.go b/glide.go index 486b813b..f1a4162a 100644 --- a/glide.go +++ b/glide.go @@ -169,7 +169,18 @@ func commands() []cli.Command { When adding a new dependency Glide will perform an update to work out the the versions to use from the dependency tree. This will generate an updated glide.lock file with specific locked versions to use. - `, + + If you are storing the outside dependencies in your version control system + (VCS), also known as vendoring, there are a few flags that may be useful. + The '--update-vendored' flag will cause Glide to update packages when VCS + information is unavailable. This can be used with the '--strip-vcs' flag which + will strip VCS data found in the vendor directory. This is useful for + removing VCS data from transitive dependencies and initial setups. The + '--strip-vendor' flag will remove any nested 'vendor' folders and + 'Godeps/_workspace' folders after an update (along with undoing any Godep + import rewriting). Note, The Godeps specific functionality is deprecated and + will be removed when most Godeps users have migrated to using the vendor + folder.`, Flags: []cli.Flag{ cli.BoolFlag{ Name: "insecure", @@ -462,10 +473,17 @@ Example: It will create a glide.yaml file from the Godeps data, and then update. This has no effect if '--no-recursive' is set. - If the '--update-vendored' flag (aliased to '-u') is present vendored - dependencies, stored in your projects VCS repository, will be updated. This - works by removing the old package, checking out an the repo and setting the - version, and removing the VCS directory. + If you are storing the outside dependencies in your version control system + (VCS), also known as vendoring, there are a few flags that may be useful. + The '--update-vendored' flag will cause Glide to update packages when VCS + information is unavailable. This can be used with the '--strip-vcs' flag which + will strip VCS data found in the vendor directory. This is useful for + removing VCS data from transitive dependencies and initial setups. The + '--strip-vendor' flag will remove any nested 'vendor' folders and + 'Godeps/_workspace' folders after an update (along with undoing any Godep + import rewriting). Note, The Godeps specific functionality is deprecated and + will be removed when most Godeps users have migrated to using the vendor + folder. By default, packages that are discovered are considered transient, and are not stored in the glide.yaml file. The --file=NAME.yaml flag allows you From f68e084650b0b396f3bd5896888130a17c16a963 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 21 Mar 2016 21:40:40 -0400 Subject: [PATCH 5/5] Updating sub-packages for testing --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7adc2808..777d92c7 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ install: build install -m 755 ./glide ${DESTDIR}/usr/local/bin/glide test: - go test . ./gb ./path ./action ./tree ./util ./godep ./gpm ./cfg ./dependency ./importer ./msg ./repo + go test . ./gb ./path ./action ./tree ./util ./godep ./godep/strip ./gpm ./cfg ./dependency ./importer ./msg ./repo clean: rm -f ./glide.test