mirror of
https://github.com/thegeeklab/wp-git-action.git
synced 2024-06-02 18:29:41 +02:00
cleanup
This commit is contained in:
parent
e88a8c2365
commit
43243662de
|
@ -30,6 +30,37 @@ func TestAdd(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIsCleanTree(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "clean working tree",
|
||||
repo: Repository{
|
||||
WorkDir: "/path/to/repo",
|
||||
},
|
||||
want: []string{gitBin, "diff-index", "--quiet", "HEAD", "--ignore-submodules"},
|
||||
},
|
||||
{
|
||||
name: "unclean working tree",
|
||||
repo: Repository{
|
||||
WorkDir: "/path/to/unclean/repo",
|
||||
},
|
||||
want: []string{gitBin, "diff-index", "--quiet", "HEAD", "--ignore-submodules"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.IsCleanTree()
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
assert.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
@ -163,14 +163,8 @@ func (p *Plugin) Execute() error {
|
|||
batchCmd = append(batchCmd, p.Settings.Repo.ConfigUserEmail())
|
||||
batchCmd = append(batchCmd, p.Settings.Repo.ConfigSSLVerify(p.Network.InsecureSkipVerify))
|
||||
|
||||
for _, cmd := range batchCmd {
|
||||
if cmd == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ExecBatch(batchCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, actionStr := range p.Settings.Action.Value() {
|
||||
|
@ -234,17 +228,7 @@ func (p *Plugin) handleClone() error {
|
|||
batchCmd = append(batchCmd, p.Settings.Repo.FetchSource())
|
||||
batchCmd = append(batchCmd, p.Settings.Repo.CheckoutHead())
|
||||
|
||||
for _, cmd := range batchCmd {
|
||||
if cmd == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return ExecBatch(batchCmd)
|
||||
}
|
||||
|
||||
// HandleCommit commits changes locally.
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -26,3 +28,18 @@ func WriteNetrc(path, machine, login, password string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExecBatch executes a batch of commands. If any command in the batch fails, the function will return the error.
|
||||
func ExecBatch(batchCmd []*types.Cmd) error {
|
||||
for _, cmd := range batchCmd {
|
||||
if cmd == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user