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

Commit

Permalink
Sort manifest sections before writing to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs committed Mar 22, 2017
1 parent cabd1a9 commit 8652142
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package dep

import (
"io"
"sort"

"github.com/pelletier/go-toml"
"github.com/pkg/errors"
Expand Down Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions testdata/manifest/golden.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 8652142

Please sign in to comment.