fix: ensure to init/commit the new recipe repo
continuous-integration/drone/push Build is passing Details

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

View File

@ -82,6 +82,11 @@ The new example repository is cloned to ~/.abra/apps/<recipe>.
}
}
newGitRepo := path.Join(config.APPS_DIR, recipeName)
if err := git.Init(newGitRepo, true); err != nil {
logrus.Fatal(err)
}
logrus.Infof(
"new recipe '%s' created in %s, happy hacking!\n",
recipeName, path.Join(config.APPS_DIR, recipeName),

38
pkg/git/init.go Normal file
View File

@ -0,0 +1,38 @@
package git
import (
"github.com/go-git/go-git/v5"
gitPkg "github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
)
// Init inits a new repo and commits all the stuff if you want
func Init(repoPath string, commit bool) error {
if _, err := gitPkg.PlainInit(repoPath, false); err != nil {
logrus.Fatal(err)
}
logrus.Debugf("initialised new git repo in %s", repoPath)
if commit {
commitRepo, err := git.PlainOpen(repoPath)
if err != nil {
logrus.Fatal(err)
}
commitWorktree, err := commitRepo.Worktree()
if err != nil {
logrus.Fatal(err)
}
if err := commitWorktree.AddGlob("**"); err != nil {
return err
}
if _, err = commitWorktree.Commit("init", &git.CommitOptions{}); err != nil {
return err
}
logrus.Debugf("init committed all files for new git repo in %s", repoPath)
}
return nil
}