fix: ensure .git repo exists

Part of coop-cloud/organising#247.
This commit is contained in:
decentral1se 2021-11-15 18:54:24 +01:00
parent 299faa1adf
commit 4a245c3e02
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 26 additions and 0 deletions

14
pkg/git/common.go Normal file
View File

@ -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
}

View File

@ -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)