Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit b0a32a7

Browse files
committed
config: git modules config
1 parent ec28bd3 commit b0a32a7

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

config/modules.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package config
2+
3+
import "errors"
4+
5+
var (
6+
ErrModuleEmptyURL = errors.New("module config: empty URL")
7+
ErrModuleEmptyPath = errors.New("module config: empty path")
8+
)
9+
10+
const DefaultModuleBranch = "master"
11+
12+
// Modules defines the submodules properties
13+
type Modules map[string]*Module
14+
15+
// Module defines a submodule
16+
// https://www.kernel.org/pub/software/scm/git/docs/gitmodules.html
17+
type Module struct {
18+
// Path defines the path, relative to the top-level directory of the Git
19+
// working tree,
20+
Path string
21+
// URL defines a URL from which the submodule repository can be cloned.
22+
URL string
23+
// Branch is a remote branch name for tracking updates in the upstream
24+
// submodule.
25+
Branch string
26+
}
27+
28+
// Validate validate the fields and set the default values
29+
func (m *Module) Validate() error {
30+
if m.Path == "" {
31+
return ErrModuleEmptyPath
32+
}
33+
34+
if m.URL == "" {
35+
return ErrModuleEmptyURL
36+
}
37+
38+
if m.Branch == "" {
39+
m.Branch = DefaultModuleBranch
40+
}
41+
42+
return nil
43+
}

config/modules_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package config
2+
3+
import . "gopkg.in/check.v1"
4+
5+
type ModuleSuite struct{}
6+
7+
var _ = Suite(&ModuleSuite{})
8+
9+
func (s *ModuleSuite) TestModuleValidateMissingURL(c *C) {
10+
m := &Module{Path: "foo"}
11+
c.Assert(m.Validate(), Equals, ErrModuleEmptyURL)
12+
}
13+
14+
func (s *ModuleSuite) TestModuleValidateMissingName(c *C) {
15+
m := &Module{URL: "bar"}
16+
c.Assert(m.Validate(), Equals, ErrModuleEmptyPath)
17+
}
18+
19+
func (s *ModuleSuite) TestModuleValidateDefault(c *C) {
20+
m := &Module{Path: "foo", URL: "http://foo/bar"}
21+
c.Assert(m.Validate(), IsNil)
22+
c.Assert(m.Branch, Equals, DefaultModuleBranch)
23+
}

0 commit comments

Comments
 (0)