This repository has been archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
remote_repo_cmds.go
60 lines (51 loc) · 1.66 KB
/
remote_repo_cmds.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
package src
import (
"log"
"sourcegraph.com/sourcegraph/go-flags"
"sourcegraph.com/sourcegraph/go-sourcegraph/sourcegraph"
)
func initRemoteRepoCmds(remoteGroup *flags.Command) {
c, err := remoteGroup.AddCommand("add",
"add the local repository to the remote",
"The add command creates a remote repository corresponding to the current local repository.",
&remoteAddCmd,
)
if err != nil {
log.Fatal(err)
}
// Set defaults.
openLocalRepo()
if localRepo != nil {
if localRepo.CloneURL != "" {
//SetOptionDefaultValue(c.Group, "uri", localRepo.URI())
SetOptionDefaultValue(c.Group, "clone-url", localRepo.CloneURL)
}
SetOptionDefaultValue(c.Group, "vcs", localRepo.VCSType)
}
}
type RemoteAddCmd struct {
VCSType string `long:"vcs" description:"VCS type" required:"yes"`
CloneURL string `long:"clone-url" description:"clone URL" required:"yes"`
}
var remoteAddCmd RemoteAddCmd
func (c *RemoteAddCmd) Execute(args []string) error {
cl := NewAPIClientWithAuthIfPresent()
if lrepo, _ := openLocalRepo(); lrepo != nil {
if c.CloneURL != lrepo.CloneURL {
log.Printf("# Warning: you are creating a remote repository with a clone URL (%q) that doesn't match that of the current dir's repository (%q).", c.CloneURL, lrepo.CloneURL)
}
if c.VCSType != lrepo.VCSType {
log.Printf("# Warning: you are creating a remote repository with a VCS type (%q) that doesn't match that of the current dir's repository (%q).", c.VCSType, lrepo.VCSType)
}
}
newRepo := sourcegraph.NewRepoSpec{
Type: c.VCSType,
CloneURLStr: c.CloneURL,
}
rrepo, _, err := cl.Repos.Create(newRepo)
if err != nil {
return err
}
printRemoteRepo(rrepo)
return nil
}