diff --git a/manifest.go b/manifest.go index f9bf1b8285..054976242c 100644 --- a/manifest.go +++ b/manifest.go @@ -6,6 +6,7 @@ package dep import ( "io" + "sort" "github.com/pelletier/go-toml" "github.com/pkg/errors" @@ -128,12 +129,34 @@ func (m *Manifest) toRaw() rawManifest { for n, prj := range m.Dependencies { raw.Dependencies = append(raw.Dependencies, toRawProject(n, prj)) } + sort.Sort(sortedRawProjects(raw.Dependencies)) + for n, prj := range m.Ovr { raw.Overrides = append(raw.Overrides, toRawProject(n, prj)) } + sort.Sort(sortedRawProjects(raw.Overrides)) + return raw } +// TODO(carolynvs) when gps is moved, we can use the unexported gps.sortedConstraints +type sortedRawProjects []rawProject + +func (s sortedRawProjects) Len() int { return len(s) } +func (s sortedRawProjects) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s sortedRawProjects) Less(i, j int) bool { + l, r := s[i], s[j] + + if l.Name < r.Name { + return true + } + if r.Name < l.Name { + return false + } + + return l.Source < r.Source +} + func (m *Manifest) MarshalTOML() (string, error) { raw := m.toRaw() diff --git a/testdata/manifest/golden.toml b/testdata/manifest/golden.toml index f3c4759d04..7de52e5089 100644 --- a/testdata/manifest/golden.toml +++ b/testdata/manifest/golden.toml @@ -1,13 +1,13 @@ ignores = ["github.com/foo/bar"] -[[dependencies]] - name = "github.com/sdboyer/gps" - version = ">=0.12.0, <1.0.0" - [[dependencies]] name = "github.com/babble/brook" revision = "d05d5aca9f895d19e9265839bffeadd74a2d2ecb" +[[dependencies]] + name = "github.com/sdboyer/gps" + version = ">=0.12.0, <1.0.0" + [[overrides]] branch = "master" name = "github.com/sdboyer/gps"