/
current_version.go
77 lines (57 loc) · 1.5 KB
/
current_version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"strings"
"github.com/vito/gocart/command_runner"
"github.com/vito/gocart/dependency"
"github.com/vito/gocart/repository"
)
type DependencyStatus struct {
VersionMatches bool
CurrentVersion string
Delta int
DeltaLog string
}
func findCurrentVersion(dep dependency.Dependency) string {
repoPath := dep.FullPath(GOPATH)
repo, err := repository.New(repoPath, command_runner.New(false))
if err != nil {
return ""
}
currentVersion, err := repo.CurrentVersion()
if err != nil {
return ""
}
return currentVersion
}
func getDependencyStatus(dep dependency.Dependency) *DependencyStatus {
repoPath := dep.FullPath(GOPATH)
repo, err := repository.New(repoPath, command_runner.New(false))
if err != nil {
return nil
}
status := &DependencyStatus{}
status.CurrentVersion = findCurrentVersion(dep)
status.VersionMatches = status.CurrentVersion == dep.Version
if status.VersionMatches {
return status
}
newer := true
logOutput, err := repo.Log(dep.Version, status.CurrentVersion)
// git or hg with both refs will show empty if newer..older
if len(logOutput) == 0 {
newer = false
}
// either bazaar, or dep.Version is not fetched
if err != nil {
newer = false
}
if newer {
status.DeltaLog = logOutput
status.Delta = len(strings.Split(status.DeltaLog, "\n")) - 1
} else {
logOutput, _ := repo.Log(status.CurrentVersion, dep.Version)
status.DeltaLog = logOutput
status.Delta = -(len(strings.Split(status.DeltaLog, "\n")) - 1)
}
return status
}