Skip to content

Commit

Permalink
Add contextdir for multi-directory git handling
Browse files Browse the repository at this point in the history
  • Loading branch information
redhatrises committed May 24, 2018
1 parent fbc7f10 commit 7915de0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions commands/get/resources/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ func (g *vcsAndLocalFSGetter) GetRemoteResources(destination string, subfolder s

// Clone repo
log.Printf("Attempting to clone %v into %s\n", entry, tempPath)

// If contextdir is defined, switch to that dir for content
if entry.GetContextDir() != "" {
tempPath = filepath.Join(tempPath, entry.GetContextDir())
}

err := g.Downloader.DownloadRepo(entry, tempPath)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions commands/get/resources/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func createMockRemoteSource() common.RemoteSource {
// Setup remoteSource mock
remoteSource := new(mocks.RemoteSource)
remoteSource.On("GetURL").Return("")
remoteSource.On("GetContextDir").Return("")
remoteSource.On("GetConfigFile").Return("")
return remoteSource
}
Expand Down
14 changes: 14 additions & 0 deletions lib/common/mocks/RemoteSource.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ func (_m *RemoteSource) GetURL() string {
return r0
}

// GetContextDir provides a mock function with given fields:
func (_m *RemoteSource) GetContextDir() string {
ret := _m.Called()

var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}

return r0
}

var _ common.RemoteSource = (*RemoteSource)(nil)
3 changes: 3 additions & 0 deletions lib/common/opencontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ type OpenControl interface {
//
// GetURL returns the URL of the resource.
//
// GetContextDir returns the specific directory containing the OpenControl content.
//
// GetRevision returns the specific revision of the resource.
//
// GetConfigFile returns the config file to look at once the resource is downloaded.
type RemoteSource interface {
GetURL() string
GetContextDir() string
GetRevision() string
GetConfigFile() string
}
6 changes: 6 additions & 0 deletions lib/opencontrol/versions/1.0.0/opencontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Metadata struct {
type VCSEntry struct {
URL string `yaml:"url"`
Revision string `yaml:"revision"`
ContextDir string `yaml:"contextdir"`
Path string `yaml:"path"`
}

Expand Down Expand Up @@ -103,3 +104,8 @@ func (e VCSEntry) GetRevision() string {
func (e VCSEntry) GetURL() string {
return e.URL
}

// GetContextDir returns the dir containing content in the vcs resource.
func (e VCSEntry) GetContextDir() string {
return e.ContextDir
}

0 comments on commit 7915de0

Please sign in to comment.