Skip to content

Commit

Permalink
Enable the use of files for components and don't fail on same repo
Browse files Browse the repository at this point in the history
- Fixes #301
  • Loading branch information
redhatrises committed Jun 15, 2018
1 parent d4d39a8 commit 199dd17
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/cli/get/resources/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ func (g *vcsAndLocalFSGetter) copyLocalResource(resourceSource string,
resourceDestination string, recursively bool) error {
var err error
log.Printf("Attempting to copy local resource %s into %s\n", resourceSource, resourceDestination)
if fi, err := os.Stat(resourceSource); err == nil {
if !fi.Mode().IsDir() {
recursively = false
}
}

if recursively {
log.Printf("Copying local resource %s recursively into %s\n",
resourceSource, resourceDestination)
Expand Down
32 changes: 28 additions & 4 deletions tools/vcs/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package vcs
import (
"fmt"
"log"
"os"
"path/filepath"

"github.com/Masterminds/vcs"
)
Expand Down Expand Up @@ -35,11 +37,18 @@ func (m Manager) Clone(url string, revision string, dir string) error {
if err != nil {
return fmt.Errorf(errorContainer, repoInitFailed, url, revision, dir, err.Error())
}
log.Printf("Cloning %s into %s\n", url, dir)
err = repo.Get()
if err != nil {
return fmt.Errorf(errorContainer, repoCloneFailed, url, revision, dir, err.Error())

files := GetVCSFolderContents(dir)
if len(files) == 1 {
log.Printf("Cloning %s into %s\n", url, dir)
err = repo.Get()
if err != nil {
return fmt.Errorf(errorContainer, repoCloneFailed, url, revision, dir, err.Error())
}
} else {
log.Printf("Repository already exists. Skipping....")
}

if revision != "" {
log.Printf("Checking out revision %s for repo %s\n", revision, url)
err = repo.UpdateVersion(revision)
Expand All @@ -51,3 +60,18 @@ func (m Manager) Clone(url string, revision string, dir string) error {
}
return nil
}

// GetVCSFolderContents determines if there are actual files in the VCS dir
func GetVCSFolderContents(directory string) []string {
var files []string

err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
return err
}

return files
}

0 comments on commit 199dd17

Please sign in to comment.