Skip to content

Commit

Permalink
pkgspec: add HasOrigin and use in context when setting Origin
Browse files Browse the repository at this point in the history
  • Loading branch information
kardianos committed Sep 1, 2016
1 parent be50900 commit 350e502
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
9 changes: 7 additions & 2 deletions context/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ func (ctx *Context) modify(ps *pkgspec.Pkg, mod Modify, mops []ModifyOption) err
pkg.Origin = ps.PathOrigin()
pkg.Path = ps.Path
}
if ps.Origin != pkg.Origin {

pkg.HasOrigin = ps.HasOrigin
if ps.HasOrigin {
pkg.Origin = ps.Origin
}

Expand Down Expand Up @@ -406,7 +408,10 @@ func (ctx *Context) modifyAdd(pkg *Package, uncommitted bool) error {
if pkg.IncludeTree {
vp.Tree = pkg.IncludeTree
}
vp.Origin = pkg.Origin

if pkg.HasOrigin {
vp.Origin = pkg.Origin
}
if pkg.Path != pkg.Local && pkg.inVendor && vp.Add {
vp.Origin = pkg.Local
}
Expand Down
1 change: 1 addition & 0 deletions pkgspec/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Pkg struct {
IncludeTree bool
MatchTree bool
HasVersion bool
HasOrigin bool
Version string

Uncommitted bool
Expand Down
3 changes: 2 additions & 1 deletion pkgspec/pkgspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func Parse(currentGoPath, s string) (*Pkg, error) {
}

pkg := &Pkg{
Path: s,
Path: s,
HasOrigin: (originIndex >= 0),
}

if versionIndex > 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkgspec/pkgspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestParse(t *testing.T) {
{Spec: "abc/def::", Err: ErrEmptyOrigin},
{Spec: "abc/def::foo/bar/vendor/abc/def"},
{Spec: "abc/def::foo/bar/vendor/abc/def@"},
{Spec: "abc/def::foo/bar/vendor/abc/[email protected]", Pkg: &Pkg{Path: "abc/def", Origin: "foo/bar/vendor/abc/def", HasVersion: true, Version: "v1.2.3"}},
{Spec: "abc/def::foo/bar/vendor/abc/[email protected]", Pkg: &Pkg{Path: "abc/def", HasOrigin: true, Origin: "foo/bar/vendor/abc/def", HasVersion: true, Version: "v1.2.3"}},
{Spec: "abc/def@", Pkg: &Pkg{Path: "abc/def", HasVersion: true}},
{Spec: "abc/[email protected]", Pkg: &Pkg{Path: "abc/def", HasVersion: true, Version: "v1.2.3"}},
{Spec: "./[email protected]", Str: "abc/[email protected]", Pkg: &Pkg{Path: "abc/def", HasVersion: true, Version: "v1.2.3"}, WD: "abc/"},
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestParse(t *testing.T) {
}
if item.Pkg != nil {
diffA := pkg.Path != item.Pkg.Path || pkg.Origin != item.Pkg.Origin || pkg.Version != item.Pkg.Version
diffB := pkg.HasVersion != item.Pkg.HasVersion || pkg.MatchTree != item.Pkg.MatchTree || pkg.IncludeTree != item.Pkg.IncludeTree
diffB := pkg.HasVersion != item.Pkg.HasVersion || pkg.HasOrigin != item.Pkg.HasOrigin || pkg.MatchTree != item.Pkg.MatchTree || pkg.IncludeTree != item.Pkg.IncludeTree
if diffA || diffB {
t.Errorf("For %q, pkg detail diff: got %#v", item.Spec, pkg)
}
Expand Down

0 comments on commit 350e502

Please sign in to comment.