-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (38 loc) · 1.07 KB
/
main.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
// Command fetch_repo is similar to "go get -d" but it works even if the given
// repository path is not a buildable Go package and it checks out a specific
// revision rather than the latest revision.
//
// The difference between fetch_repo and "git clone" or {new_,}git_repository is
// that fetch_repo recognizes import redirection of Go and it supports other
// version control systems than git.
//
// These differences help us to manage external Go repositories in the manner of
// Bazel.
package main
import (
"flag"
"fmt"
"log"
"golang.org/x/tools/go/vcs"
)
var (
remote = flag.String("remote", "", "Go importpath to the repository fetch")
rev = flag.String("rev", "", "target revision")
dest = flag.String("dest", "", "destination directory")
)
func run() error {
r, err := vcs.RepoRootForImportPath(*remote, true)
if err != nil {
return err
}
if *remote != r.Root {
return fmt.Errorf("not a root of a repository: %s", *remote)
}
return r.VCS.CreateAtRev(*dest, r.Repo, *rev)
}
func main() {
flag.Parse()
if err := run(); err != nil {
log.Fatal(err)
}
}