Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
Merge branch 'pr/343'
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Muller committed Dec 17, 2015
2 parents cba897e + dcd1392 commit fe5ce70
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 46 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v41 2015/12/17

* Don't rewrite packages outside of the project. This would happen if you specified
an external package for vendoring when you ran `goodep save -r ./... github.com/some/other/package`

# v40 2015/12/17

* When downloading a dependency, create the base directory if needed.
Expand Down
38 changes: 26 additions & 12 deletions save.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ The dependency list is a JSON document with the following structure:
Any packages already present in the list will be left unchanged.
To update a dependency to a newer revision, use 'godep update'.
If -r is given, import statements will be rewritten to refer
directly to the copied source code. This is not compatible with the
vendor experiment.
If -r is given, import statements will be rewritten to refer directly
to the copied source code. This is not compatible with the vendor
experiment. Note that this will not rewrite the statements in the
files outside the project.
If -t is given, test files (*_test.go files + testdata directories) are
also saved.
Expand Down Expand Up @@ -81,21 +82,33 @@ func runSave(cmd *Command, args []string) {
}
}

func dotPackageImportPath() (string, error) {
func dotPackage() (*build.Package, error) {
dir, err := filepath.Abs(".")
if err != nil {
return "", err
return nil, err
}
p, err := build.ImportDir(dir, build.FindOnly)
return p.ImportPath, err
return build.ImportDir(dir, build.FindOnly)
}

func projectPackages(dDir string, a []*Package) []*Package {
var projPkgs []*Package
dotDir := fmt.Sprintf("%s%c", dDir, filepath.Separator)
for _, p := range a {
pkgDir := fmt.Sprintf("%s%c", p.Dir, filepath.Separator)
if strings.HasPrefix(pkgDir, dotDir) {
projPkgs = append(projPkgs, p)
}
}
return projPkgs
}

func save(pkgs []string) error {
dip, err := dotPackageImportPath()
dp, err := dotPackage()
if err != nil {
return err
}
debugln("dotPackageImportPath:", dip)
debugln("dotPackageImportPath:", dp.ImportPath)
debugln("dotPackageDir:", dp.Dir)

cv, err := goVersion()
if err != nil {
Expand All @@ -114,7 +127,7 @@ func save(pkgs []string) error {
printVersionWarnings(gold.GoVersion)

gnew := &Godeps{
ImportPath: dip,
ImportPath: dp.ImportPath,
GoVersion: gold.GoVersion,
}

Expand All @@ -132,7 +145,8 @@ func save(pkgs []string) error {
debugln("LoadPackages", pkgs)
ppln(a)

err = gnew.fill(a, dip)
projA := projectPackages(dp.Dir, a)
err = gnew.fill(a, dp.ImportPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -191,7 +205,7 @@ func save(pkgs []string) error {
rewritePaths = append(rewritePaths, dep.ImportPath)
}
}
return rewrite(a, dip, rewritePaths)
return rewrite(projA, dp.ImportPath, rewritePaths)
}

func printVersionWarnings(ov string) {
Expand Down

1 comment on commit fe5ce70

@owenthereal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.