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

Commit 66e20d5

Browse files
authored
Merge pull request #994 from sdboyer/add-hoist-from-lock
Fix missing branch in dep ensure -add: introduce hoist from lock
2 parents 69a26cc + 21d3511 commit 66e20d5

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

cmd/dep/ensure.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77
import (
88
"bytes"
99
"flag"
10+
"fmt"
1011
"go/build"
1112
"os"
1213
"path/filepath"
@@ -585,13 +586,28 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
585586
reqlist = append(reqlist, path)
586587
}
587588

588-
if !gps.IsAny(instr.constraint) || instr.id.Source != "" {
589-
appender.Constraints[pr] = gps.ProjectProperties{
590-
Source: instr.id.Source,
591-
Constraint: instr.constraint,
589+
if instr.typ&isInManifest == 0 {
590+
var pp gps.ProjectProperties
591+
var found bool
592+
for _, proj := range solution.Projects() {
593+
// We compare just ProjectRoot instead of the whole
594+
// ProjectIdentifier here because an empty source on the input side
595+
// could have been converted into a source by the solver.
596+
if proj.Ident().ProjectRoot == pr {
597+
found = true
598+
pp = getProjectPropertiesFromVersion(proj.Version())
599+
break
600+
}
601+
}
602+
if !found {
603+
panic(fmt.Sprintf("unreachable: solution did not contain -add argument %s, but solver did not fail", pr))
604+
}
605+
pp.Source = instr.id.Source
606+
607+
if !gps.IsAny(instr.constraint) {
608+
pp.Constraint = instr.constraint
592609
}
593-
//} else {
594-
// TODO(sdboyer) hoist a constraint into the manifest from the lock
610+
appender.Constraints[pr] = pp
595611
}
596612
}
597613

cmd/dep/testdata/harness_tests/ensure/add/all-new-double/final/Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
[[constraint]]
33
name = "github.com/sdboyer/deptest"
44
version = "1.0.0"
5+
6+
[[constraint]]
7+
branch = "master"
8+
name = "github.com/sdboyer/deptesttres"

cmd/dep/testdata/harness_tests/ensure/add/all-new/final/Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
[[constraint]]
33
branch = "master"
44
name = "github.com/sdboyer/deptesttres"
5+
6+
[[constraint]]
7+
name = "github.com/sdboyer/deptest"
8+
version = "1.0.0"

0 commit comments

Comments
 (0)