forked from toolshed/abra
.gitea
cli
cmd
pkg
app
autocomplete
catalogue
client
compose
config
container
context
dns
formatter
git
branch.go
clone.go
commit.go
common.go
init.go
push.go
read.go
remote.go
integration
jsontable
limit
lint
recipe
secret
server
service
ssh
test
upstream
web
scripts
tests
.dockerignore
.drone.yml
.e2e.env.sample
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
39 lines
869 B
Go
39 lines
869 B
Go
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.AddWithOptions(&git.AddOptions{All: true}); 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
|
|
}
|