-
Notifications
You must be signed in to change notification settings - Fork 3
/
restore.go
61 lines (56 loc) · 1.18 KB
/
restore.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
package main
import (
"log"
"os"
"path/filepath"
)
var cmdRestore = &Command{
Usage: "restore",
Short: "check out listed dependency versions in GOPATH",
Long: `
Restore checks out the Deps-specified version of each package in GOPATH.
`,
Run: runRestore,
}
func runRestore(cmd *Command, args []string) {
g, err := ReadAndLoadDeps(findDepsJSON())
if err != nil {
log.Fatalln(err)
}
hadError := false
for _, dep := range g.Deps {
err := restore(dep)
if err != nil {
log.Println("restore:", err)
hadError = true
}
}
if hadError {
os.Exit(1)
}
}
// restore downloads the given dependency and checks out
// the given revision.
func restore(dep Dependency) error {
// make sure pkg exists somewhere in GOPATH
err := runIn(".", "go", "get", "-d", dep.ImportPath)
if err != nil {
return err
}
ps, err := LoadPackages(dep.ImportPath)
if err != nil {
return err
}
pkg := ps[0]
if !dep.vcs.exists(pkg.Dir, dep.Rev) {
dep.vcs.vcs.Download(pkg.Dir)
}
return dep.vcs.RevSync(pkg.Dir, dep.Rev)
}
func findDepsJSON() (path string) {
dir := findDeps()
if dir == "" {
log.Fatalln("No Deps found (or in any parent directory)")
}
return filepath.Join(dir, "Deps")
}