fix(git): use git binary for "git add"

This commit is contained in:
DataHearth 2022-04-07 20:53:19 +02:00
parent 584fe09fe2
commit 35d8210ca9
No known key found for this signature in database
GPG Key ID: E88FD356ACC5F3C4
2 changed files with 15 additions and 21 deletions

View File

@ -3,6 +3,7 @@ package mapper
import (
"errors"
"os"
"os/exec"
"time"
"github.com/go-git/go-git/v5"
@ -137,29 +138,20 @@ func (r *Repository) PushChanges(msg string, newLines, removedLines []string) er
return err
}
for _, l := range newLines {
if err := w.AddWithOptions(&git.AddOptions{
Path: l,
}); err != nil {
return err
}
}
for _, l := range removedLines {
if err := w.AddWithOptions(&git.AddOptions{
Path: l,
}); err != nil {
return err
}
// TODO: investigated why w.AddWithOptions doesn't add removed files and sometimes .index
cmd := exec.Command("git", "add", ".")
cmd.Dir = r.repoPath
if err := cmd.Run(); err != nil {
return err
}
return nil
// if _, err := w.Commit(msg, &git.CommitOptions{
// Author: r.GetAuthor(),
// }); err != nil {
// return err
// }
if _, err := w.Commit(msg, &git.CommitOptions{
Author: r.GetAuthor(),
}); err != nil {
return err
}
// return r.repository.Push(&git.PushOptions{})
return r.repository.Push(&git.PushOptions{})
}
func (r *Repository) GetWorktree() (*git.Worktree, error) {

View File

@ -86,9 +86,10 @@ func (i *Index) filter(newLines []string) map[string]bool {
func (i *Index) Write(newLines []string) error {
lines := i.filter(newLines)
linesNumber := len(lines)
var data []byte
index := 0
linesNumber := len(lines)
i.lines = []string{}
for path := range lines {
if index+1 == linesNumber {
data = append(data, []byte(fmt.Sprint(path))...)
@ -97,6 +98,7 @@ func (i *Index) Write(newLines []string) error {
}
index += 1
i.lines = append(i.lines, path)
}
os.WriteFile(i.path, data, i.perms)