diff --git a/pkg/git/common.go b/pkg/git/common.go new file mode 100644 index 00000000..ff4eb7d7 --- /dev/null +++ b/pkg/git/common.go @@ -0,0 +1,14 @@ +package git + +import ( + "fmt" + "os" +) + +// EnsureGitRepo ensures a git repo .git folder exists +func EnsureGitRepo(repoPath string) error { + if _, err := os.Stat(repoPath); os.IsNotExist(err) { + return fmt.Errorf("no .git directory in %s?", repoPath) + } + return nil +} diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index 61be4dc7..f6edf7ee 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -108,6 +108,10 @@ func EnsureExists(recipe string) error { } } + if err := gitPkg.EnsureGitRepo(recipeDir); err != nil { + return err + } + return nil } @@ -124,6 +128,10 @@ func EnsureVersion(recipeName, version string) error { return fmt.Errorf("'%s' has locally unstaged changes", recipeName) } + if err := gitPkg.EnsureGitRepo(recipeDir); err != nil { + return err + } + repo, err := git.PlainOpen(recipeDir) if err != nil { return err @@ -184,6 +192,10 @@ func EnsureLatest(recipeName string) error { return fmt.Errorf("'%s' has locally unstaged changes", recipeName) } + if err := gitPkg.EnsureGitRepo(recipeDir); err != nil { + return err + } + logrus.Debugf("attempting to open git repository in '%s'", recipeDir) repo, err := git.PlainOpen(recipeDir)