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
}
