6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 14:31:49 +00:00

Add helpers ability to create multiple commits

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-18 13:55:57 +02:00
parent b2e5f9178b
commit 14614b3549

View File

@@ -89,7 +89,25 @@ func createCommit(repo *git.Repository, message string) error {
When: time.Date(2000, 01, 01, 16, 00, 00, 0, time.UTC),
}
_, err = repo.CreateCommit("HEAD", signature, signature, message, tree)
empty, err := repo.IsEmpty()
if err != nil {
return errors.Wrap(err, "failed cheching if repo is empty")
}
if !empty {
currentBranch, err := repo.Head()
if err != nil {
return errors.Wrap(err, "failed getting current branch")
}
currentTip, err := repo.LookupCommit(currentBranch.Target())
if err != nil {
return errors.Wrap(err, "failed getting current tip")
}
_, err = repo.CreateCommit("HEAD", signature, signature, message, tree, currentTip)
} else {
_, err = repo.CreateCommit("HEAD", signature, signature, message, tree)
}
if err != nil {
return errors.Wrap(err, "failed creating commit")
}