fix(git): deleted files are not pushed

This commit is contained in:
DataHearth 2022-03-01 19:52:02 +01:00
parent 94b2838f7e
commit a85165e8fe
2 changed files with 18 additions and 4 deletions

View File

@ -122,6 +122,8 @@ var saveCmd = &cobra.Command{
}
if viper.GetBool("push") {
pterm.DefaultSection.Println("Pushing items")
s, _ := pterm.DefaultSpinner.WithShowTimer(true).WithRemoveWhenDone(false).Start("Pushing changes to remote repository")
if err := repo.PushChanges(viper.GetString("message")); err != nil {

View File

@ -3,6 +3,7 @@ package mapper
import (
"errors"
"os"
"os/exec"
"time"
"github.com/go-git/go-git/v5"
@ -123,17 +124,28 @@ func (r *Repository) PushChanges(msg string) error {
return err
}
if _, err := w.Add("."); err != nil {
return err
// TODO: debug why deleted files/folders aren't added to index
// if err := w.AddWithOptions(&git.AddOptions{
// All: true,
// }); err != nil {
// return err
// }
cmd := exec.Command("git", "add", ".")
cmd.Dir = r.repoPath
if err := cmd.Run(); err != nil {
return errors.New("failed to add files to git index: " + err.Error())
}
w.Commit(msg, &git.CommitOptions{
if _, err := w.Commit(msg, &git.CommitOptions{
Author: &object.Signature{
Name: r.author.name,
Email: r.author.email,
When: time.Now(),
},
})
}); err != nil {
return err
}
return r.repository.Push(&git.PushOptions{})
}