fix(git): deleted files are not pushed
This commit is contained in:
parent
94b2838f7e
commit
a85165e8fe
|
@ -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 {
|
||||
|
|
|
@ -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{})
|
||||
}
|
||||
|
|
Reference in New Issue