forked from toolshed/abra
.gitea
cli
cmd
pkg
app
autocomplete
catalogue
client
config
container
context
dns
envfile
formatter
git
add.go
branch.go
clone.go
commit.go
common.go
diff.go
init.go
push.go
read.go
remote.go
integration
limit
lint
log
recipe
secret
server
service
ssh
test
upstream
web
scripts
tests
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package git
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"coopcloud.tech/abra/pkg/log"
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/go-git/go-git/v5/plumbing/object"
|
|
)
|
|
|
|
// Init inits a new repo and commits all the stuff if you want
|
|
func Init(repoPath string, commit bool, gitName, gitEmail string) error {
|
|
if _, err := git.PlainInit(repoPath, false); err != nil {
|
|
return fmt.Errorf("git init: %s", err)
|
|
}
|
|
log.Debugf("initialised new git repo in %s", repoPath)
|
|
|
|
if commit {
|
|
commitRepo, err := git.PlainOpen(repoPath)
|
|
if err != nil {
|
|
return fmt.Errorf("git open: %s", err)
|
|
}
|
|
|
|
commitWorktree, err := commitRepo.Worktree()
|
|
if err != nil {
|
|
return fmt.Errorf("git worktree: %s", err)
|
|
}
|
|
|
|
if err := commitWorktree.AddWithOptions(&git.AddOptions{All: true}); err != nil {
|
|
return fmt.Errorf("git add: %s", err)
|
|
}
|
|
|
|
var author *object.Signature
|
|
if gitName != "" && gitEmail != "" {
|
|
author = &object.Signature{Name: gitName, Email: gitEmail}
|
|
}
|
|
if _, err = commitWorktree.Commit("init", &git.CommitOptions{Author: author}); err != nil {
|
|
return fmt.Errorf("git commit: %s", err)
|
|
}
|
|
log.Debugf("init committed all files for new git repo in %s", repoPath)
|
|
}
|
|
|
|
return nil
|
|
}
|