abra/pkg/git/add.go
decentral1se ef108d63e1
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
refactor: use central logger
2024-07-08 00:01:28 +02:00

28 lines
420 B
Go

package git
import (
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
)
// Add adds a file to the git index.
func Add(repoPath, path string, dryRun bool) error {
repo, err := git.PlainOpen(repoPath)
if err != nil {
return err
}
worktree, err := repo.Worktree()
if err != nil {
return err
}
if dryRun {
log.Debugf("dry run: adding %s", path)
} else {
worktree.Add(path)
}
return nil
}