forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitserver.go
61 lines (52 loc) · 1.31 KB
/
gitserver.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 gitserver
import (
"fmt"
"log"
"net/url"
"github.com/spf13/cobra"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/gitserver"
"github.com/openshift/origin/pkg/gitserver/autobuild"
)
const longCommandDesc = `
Start a Git server
This command launches a Git HTTP/HTTPS server that supports push and pull, mirroring,
and automatic creation of applications on push.
%[1]s
`
// NewCommandGitServer launches a Git server
func NewCommandGitServer(name string) *cobra.Command {
cmd := &cobra.Command{
Use: name,
Short: "Start a Git server",
Long: fmt.Sprintf(longCommandDesc, gitserver.EnvironmentHelp),
Run: func(c *cobra.Command, args []string) {
err := RunGitServer()
cmdutil.CheckErr(err)
},
}
return cmd
}
func RunGitServer() error {
config, err := gitserver.NewEnviromentConfig()
if err != nil {
return err
}
link, err := autobuild.NewAutoLinkBuildsFromEnvironment()
switch {
case err == autobuild.ErrNotEnabled:
case err != nil:
log.Fatal(err)
default:
link.LinkFn = func(name string) *url.URL { return gitserver.RepositoryURL(config, name, nil) }
clones, err := link.Link()
if err != nil {
log.Printf("error: %v", err)
break
}
for name, v := range clones {
config.InitialClones[name] = v
}
}
return gitserver.Start(config)
}