Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Absorb prune into ensure #952

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"

[prune]
non-go = true
go-tests = true
unused-packages = true
25 changes: 17 additions & 8 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
if !ctx.Verbose {
logger = log.New(ioutil.Discard, "", 0)
}
return errors.WithMessage(sw.Write(p.AbsRoot, sm, true, logger), "grouped write of manifest, lock and vendor")

err = sw.Write(p.AbsRoot, sm, true, p.Manifest.PruneOptions, logger)
return errors.WithMessage(err, "grouped write of manifest, lock and vendor")
}

solution, err := solver.Solve()
Expand All @@ -273,7 +275,9 @@ func (cmd *ensureCommand) runDefault(ctx *dep.Ctx, args []string, p *dep.Project
if !ctx.Verbose {
logger = log.New(ioutil.Discard, "", 0)
}
return errors.Wrap(sw.Write(p.AbsRoot, sm, false, logger), "grouped write of manifest, lock and vendor")

err = sw.Write(p.AbsRoot, sm, false, p.Manifest.PruneOptions, logger)
return errors.Wrap(err, "grouped write of manifest, lock and vendor")
}

func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
Expand Down Expand Up @@ -306,7 +310,9 @@ func (cmd *ensureCommand) runVendorOnly(ctx *dep.Ctx, args []string, p *dep.Proj
if !ctx.Verbose {
logger = log.New(ioutil.Discard, "", 0)
}
return errors.WithMessage(sw.Write(p.AbsRoot, sm, true, logger), "grouped write of manifest, lock and vendor")

err = sw.Write(p.AbsRoot, sm, true, p.Manifest.PruneOptions, logger)
return errors.WithMessage(err, "grouped write of manifest, lock and vendor")
}

func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
Expand Down Expand Up @@ -401,7 +407,9 @@ func (cmd *ensureCommand) runUpdate(ctx *dep.Ctx, args []string, p *dep.Project,
if !ctx.Verbose {
logger = log.New(ioutil.Discard, "", 0)
}
return errors.Wrap(sw.Write(p.AbsRoot, sm, false, logger), "grouped write of manifest, lock and vendor")

err = sw.Write(p.AbsRoot, sm, false, p.Manifest.PruneOptions, logger)
return errors.Wrap(err, "grouped write of manifest, lock and vendor")
}

func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager, params gps.SolveParameters) error {
Expand Down Expand Up @@ -603,9 +611,8 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm

// Prep post-actions and feedback from adds.
var reqlist []string
appender := &dep.Manifest{
Constraints: make(gps.ProjectConstraints),
}
appender := dep.NewManifest()

for pr, instr := range addInstructions {
for path := range instr.ephReq {
reqlist = append(reqlist, path)
Expand Down Expand Up @@ -655,7 +662,9 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
if !ctx.Verbose {
logger = log.New(ioutil.Discard, "", 0)
}
if err := errors.Wrap(sw.Write(p.AbsRoot, sm, true, logger), "grouped write of manifest, lock and vendor"); err != nil {

err = sw.Write(p.AbsRoot, sm, true, p.Manifest.PruneOptions, logger)
if err := errors.Wrap(err, "grouped write of manifest, lock and vendor"); err != nil {
return err
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/dep/glide_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
task.WriteString("...")
g.logger.Println(task)

manifest := &dep.Manifest{
Constraints: make(gps.ProjectConstraints),
}
manifest := dep.NewManifest()

for _, pkg := range append(g.yaml.Imports, g.yaml.TestImports...) {
pc, err := g.buildProjectConstraint(pkg)
Expand Down
24 changes: 13 additions & 11 deletions cmd/dep/glide_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ func TestGlideConfig_Convert(t *testing.T) {
},
},
},
projectRoot: "github.com/sdboyer/deptest",
wantSourceRepo: "https://github.com/sdboyer/deptest.git",
matchPairedVersion: true,
wantConstraint: "^1.0.0",
wantLockCount: 1,
wantRevision: gps.Revision("ff2948a2ac8f538c4ecd55962e919d1e13e74baf"),
wantVersion: "v1.0.0",
projectRoot: "github.com/sdboyer/deptest",
wantSourceRepo: "https://github.com/sdboyer/deptest.git",
matchPairedVersion: true,
wantConstraint: "^1.0.0",
wantLockCount: 1,
wantRevision: gps.Revision("ff2948a2ac8f538c4ecd55962e919d1e13e74baf"),
wantVersion: "v1.0.0",
wantIgnoredPackages: []string{},
},
"test project": {
yaml: glideYaml{
Expand All @@ -91,10 +92,11 @@ func TestGlideConfig_Convert(t *testing.T) {
},
},
},
projectRoot: "github.com/sdboyer/deptest",
wantLockCount: 1,
wantConstraint: "^1.0.0",
wantVersion: "v1.0.0",
projectRoot: "github.com/sdboyer/deptest",
wantLockCount: 1,
wantConstraint: "^1.0.0",
wantVersion: "v1.0.0",
wantIgnoredPackages: []string{},
},
"with ignored package": {
yaml: glideYaml{
Expand Down
4 changes: 1 addition & 3 deletions cmd/dep/godep_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func (g *godepImporter) load(projectDir string) error {
func (g *godepImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) {
g.logger.Println("Converting from Godeps.json ...")

manifest := &dep.Manifest{
Constraints: make(gps.ProjectConstraints),
}
manifest := dep.NewManifest()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yay! Thank you for the constructor. 😃

lock := &dep.Lock{}

for _, pkg := range g.json.Imports {
Expand Down
7 changes: 3 additions & 4 deletions cmd/dep/gopath_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ func (g *gopathScanner) InitializeRootManifestAndLock(rootM *dep.Manifest, rootL
return err
}

g.origM = &dep.Manifest{
Constraints: g.pd.constraints,
Ovr: make(gps.ProjectConstraints),
}
g.origM = dep.NewManifest()
g.origM.Constraints = g.pd.constraints

g.origL = &dep.Lock{
P: make([]gps.LockedProject, 0, len(g.pd.ondisk)),
}
Expand Down
21 changes: 8 additions & 13 deletions cmd/dep/gopath_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ func TestGopathScanner_OverlayManifestConstraints(t *testing.T) {
v1 := gps.NewVersion("v1.0.0")
v2 := gps.NewVersion("v2.0.0")
v3 := gps.NewVersion("v3.0.0")
rootM := &dep.Manifest{
Constraints: gps.ProjectConstraints{
pi1.ProjectRoot: gps.ProjectProperties{Constraint: v1},
},
}
rootM := dep.NewManifest()
rootM.Constraints[pi1.ProjectRoot] = gps.ProjectProperties{Constraint: v1}
rootL := &dep.Lock{}
origM := dep.NewManifest()
origM.Constraints[pi1.ProjectRoot] = gps.ProjectProperties{Constraint: v2}
origM.Constraints[pi2.ProjectRoot] = gps.ProjectProperties{Constraint: v3}
gs := gopathScanner{
origM: &dep.Manifest{
Constraints: gps.ProjectConstraints{
pi1.ProjectRoot: gps.ProjectProperties{Constraint: v2},
pi2.ProjectRoot: gps.ProjectProperties{Constraint: v3},
},
},
origM: origM,
origL: &dep.Lock{},
ctx: ctx,
pd: projectData{
Expand Down Expand Up @@ -79,7 +74,7 @@ func TestGopathScanner_OverlayLockProjects(t *testing.T) {
h := test.NewHelper(t)
ctx := newTestContext(h)

rootM := &dep.Manifest{}
rootM := dep.NewManifest()
pi1 := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(testProject1)}
pi2 := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(testProject2)}
v1 := gps.NewVersion("v1.0.0")
Expand All @@ -89,7 +84,7 @@ func TestGopathScanner_OverlayLockProjects(t *testing.T) {
P: []gps.LockedProject{gps.NewLockedProject(pi1, v1, []string{})},
}
gs := gopathScanner{
origM: &dep.Manifest{Constraints: make(gps.ProjectConstraints)},
origM: dep.NewManifest(),
origL: &dep.Lock{
P: []gps.LockedProject{
gps.NewLockedProject(pi1, v2, []string{}), // ignored, already exists in lock
Expand Down
3 changes: 2 additions & 1 deletion cmd/dep/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
if !ctx.Verbose {
logger = log.New(ioutil.Discard, "", 0)
}
if err := sw.Write(root, sm, !cmd.noExamples, logger); err != nil {

if err := sw.Write(root, sm, !cmd.noExamples, p.Manifest.PruneOptions, logger); err != nil {
return errors.Wrap(err, "safe write of manifest and lock")
}

Expand Down
1 change: 0 additions & 1 deletion cmd/dep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (c *Config) Run() (exitCode int) {
&statusCommand{},
&ensureCommand{},
&hashinCommand{},
&pruneCommand{},
}

examples := [][2]string{
Expand Down
Loading