Files
abra/pkg/git/commit.go
decentral1se 53342a5dd4
All checks were successful
continuous-integration/drone/push Build is passing
feat: translation support
See #483
2025-08-19 11:39:43 +02:00

49 lines
973 B
Go

package git
import (
"errors"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/leonelquinteros/gotext"
)
// Commit runs a git commit
func Commit(repoPath, commitMessage string, dryRun bool) error {
if commitMessage == "" {
return errors.New(gotext.Get("no commit message specified?"))
}
commitRepo, err := git.PlainOpen(repoPath)
if err != nil {
return err
}
commitWorktree, err := commitRepo.Worktree()
if err != nil {
return err
}
patterns, err := GetExcludesFiles()
if err != nil {
return err
}
if len(patterns) > 0 {
commitWorktree.Excludes = append(patterns, commitWorktree.Excludes...)
}
if !dryRun {
// NOTE(d1): `All: true` does not include untracked files
_, err = commitWorktree.Commit(commitMessage, &git.CommitOptions{All: true})
if err != nil {
return err
}
log.Debug(gotext.Get("git changes commited"))
} else {
log.Debug(gotext.Get("dry run: no changes commited"))
}
return nil
}