Skip to content

Commit

Permalink
cmd/go/internal/get: complete implementation
Browse files Browse the repository at this point in the history
The original prototype only supported "go get thing"
and "go get -u" but not the obvious "go get -u thing".
Fix that.

Also add "go get -u=patch", as promised in the proposal.
(There it was called "-p", but that's a build flag already.)

Redefine "go get -m" (not implemented until now) to mean
"only update go.mod".

Fixes golang/go#24105.
Fixes golang/go#24486.

Change-Id: I981a86cf2b283f8d05e404292fa5d3482540105c
Reviewed-on: https://go-review.googlesource.com/122396
Reviewed-by: Bryan C. Mills <bcmills@google.com>
  • Loading branch information
rsc committed Jul 12, 2018
1 parent 73a132e commit 4d8d2f8
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 222 deletions.
12 changes: 11 additions & 1 deletion vendor/cmd/go/internal/modfetch/coderepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (r *codeRepo) Latest() (*RevInfo, error) {
}

func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, error) {

info2 := &RevInfo{
Name: info.Name,
Short: info.Short,
Expand Down Expand Up @@ -184,6 +183,17 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
}
}

// Do not allow a successful stat of a pseudo-version for a subdirectory
// unless the subdirectory actually does have a go.mod.
if IsPseudoVersion(info2.Version) && r.codeDir != "" {
_, _, _, err := r.findDir(info2.Version)
if err != nil {
// TODO: It would be nice to return an error like "not a module".
// Right now we return "missing go.mod", which is a little confusing.
return nil, err
}
}

return info2, nil
}

Expand Down
18 changes: 11 additions & 7 deletions vendor/cmd/go/internal/modfetch/coderepo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,10 @@ var codeRepoTests = []struct {
},
{
// package in subdirectory - github
path: "github.com/rsc/quote/buggy",
rev: "c4d4236f",
version: "v0.0.0-20180214154420-c4d4236f9242",
name: "c4d4236f92427c64bfbcf1cc3f8142ab18f30b22",
short: "c4d4236f9242",
time: time.Date(2018, 2, 14, 15, 44, 20, 0, time.UTC),
gomoderr: "missing go.mod",
// Because it's a package, Stat should fail entirely.
path: "github.com/rsc/quote/buggy",
rev: "c4d4236f",
err: "missing go.mod",
},
{
path: "gopkg.in/yaml.v2",
Expand Down Expand Up @@ -599,6 +596,10 @@ var latestTests = []struct {
path: "github.com/rsc/vgotest1",
version: "v0.0.0-20180219223237-a08abb797a67",
},
{
path: "github.com/rsc/vgotest1/subdir",
err: "missing go.mod",
},
{
path: "swtch.com/testmod",
version: "v1.1.1",
Expand Down Expand Up @@ -630,6 +631,9 @@ func TestLatest(t *testing.T) {
}
t.Fatalf("Latest(): %v", err)
}
if tt.err != "" {
t.Fatalf("Latest() = %v, want error %q", info.Version, tt.err)
}
if info.Version != tt.version {
t.Fatalf("Latest() = %v, want %v", info.Version, tt.version)
}
Expand Down
2 changes: 2 additions & 0 deletions vendor/cmd/go/internal/modfetch/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ func Import(path string, allowed func(module.Version) bool) (Repo, *RevInfo, err
// source code and check that it actually contains code for the
// target import path. To do that efficiently we will need to move
// the unzipped code cache out of ../modload into this package.
// TODO(rsc): When this happens, look carefully at the use of
// modfetch.Import in modget.getQuery.
return r, info, nil
}

Expand Down
Loading

0 comments on commit 4d8d2f8

Please sign in to comment.