mirror of
https://github.com/thegeeklab/wp-git-action.git
synced 2024-11-22 00:00:39 +00:00
fix: disable cmd trace for git config commands (#118)
This commit is contained in:
parent
c97278aa5a
commit
c1402d7c33
@ -21,6 +21,7 @@ func (r *Repository) ConfigAutocorrect() *types.Cmd {
|
|||||||
Cmd: execabs.Command(gitBin, args...),
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -38,6 +39,7 @@ func (r *Repository) ConfigUserEmail() *types.Cmd {
|
|||||||
Cmd: execabs.Command(gitBin, args...),
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -55,6 +57,7 @@ func (r *Repository) ConfigUserName() *types.Cmd {
|
|||||||
Cmd: execabs.Command(gitBin, args...),
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -72,6 +75,7 @@ func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd {
|
|||||||
Cmd: execabs.Command(gitBin, args...),
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -88,6 +92,7 @@ func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd {
|
|||||||
cmd := &types.Cmd{
|
cmd := &types.Cmd{
|
||||||
Cmd: execabs.Command(gitBin, args...),
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
|
cmd.Dir = r.WorkDir
|
||||||
cmd.SetTrace(false)
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/file"
|
"github.com/thegeeklab/wp-plugin-go/v2/file"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/util"
|
"github.com/thegeeklab/wp-plugin-go/v2/util"
|
||||||
@ -163,6 +165,8 @@ func (p *Plugin) Execute() error {
|
|||||||
action := GitAction(actionStr)
|
action := GitAction(actionStr)
|
||||||
switch action {
|
switch action {
|
||||||
case GitActionClone:
|
case GitActionClone:
|
||||||
|
log.Debug().Msg("Compose action cmd: clone")
|
||||||
|
|
||||||
cmds, err := p.handleClone()
|
cmds, err := p.handleClone()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -170,10 +174,16 @@ func (p *Plugin) Execute() error {
|
|||||||
|
|
||||||
batchCmd = append(batchCmd, cmds...)
|
batchCmd = append(batchCmd, cmds...)
|
||||||
case GitActionCommit:
|
case GitActionCommit:
|
||||||
|
log.Debug().Msg("Compose action cmd: commit")
|
||||||
|
|
||||||
batchCmd = append(batchCmd, p.handleCommit()...)
|
batchCmd = append(batchCmd, p.handleCommit()...)
|
||||||
case GitActionPush:
|
case GitActionPush:
|
||||||
|
log.Debug().Msg("Compose action cmd: push")
|
||||||
|
|
||||||
batchCmd = append(batchCmd, p.handlePush()...)
|
batchCmd = append(batchCmd, p.handlePush()...)
|
||||||
case GitActionPages:
|
case GitActionPages:
|
||||||
|
log.Debug().Msg("Compose action cmd: pages")
|
||||||
|
|
||||||
cmds, err := p.handlePages()
|
cmds, err := p.handlePages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -234,6 +244,11 @@ func (p *Plugin) handlePush() []*types.Cmd {
|
|||||||
func (p *Plugin) handlePages() ([]*types.Cmd, error) {
|
func (p *Plugin) handlePages() ([]*types.Cmd, error) {
|
||||||
var cmds []*types.Cmd
|
var cmds []*types.Cmd
|
||||||
|
|
||||||
|
log.Debug().
|
||||||
|
Str("src", p.Settings.Pages.Directory).
|
||||||
|
Str("dest", p.Settings.Repo.WorkDir).
|
||||||
|
Msg("handlePages")
|
||||||
|
|
||||||
ccmd, err := p.handleClone()
|
ccmd, err := p.handleClone()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmds, err
|
return cmds, err
|
||||||
@ -246,6 +261,7 @@ func (p *Plugin) handlePages() ([]*types.Cmd, error) {
|
|||||||
p.Settings.Pages.Delete,
|
p.Settings.Pages.Delete,
|
||||||
p.Settings.Pages.Directory,
|
p.Settings.Pages.Directory,
|
||||||
p.Settings.Repo.WorkDir,
|
p.Settings.Repo.WorkDir,
|
||||||
|
(zerolog.GlobalLevel() == zerolog.DebugLevel),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"golang.org/x/sys/execabs"
|
"golang.org/x/sys/execabs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SyncDirectories(exclude []string, del bool, src, dest string) *types.Cmd {
|
func SyncDirectories(exclude []string, del bool, src, dest string, debug bool) *types.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"-r",
|
"-r",
|
||||||
"--exclude",
|
"--exclude",
|
||||||
@ -28,6 +28,13 @@ func SyncDirectories(exclude []string, del bool, src, dest string) *types.Cmd {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
args = append(
|
||||||
|
args,
|
||||||
|
"--stats",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
args = append(
|
args = append(
|
||||||
args,
|
args,
|
||||||
".",
|
".",
|
||||||
|
@ -11,6 +11,7 @@ func TestSyncDirectories(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
exclude []string
|
exclude []string
|
||||||
del bool
|
del bool
|
||||||
|
debug bool
|
||||||
src string
|
src string
|
||||||
dest string
|
dest string
|
||||||
want []string
|
want []string
|
||||||
@ -19,6 +20,7 @@ func TestSyncDirectories(t *testing.T) {
|
|||||||
name: "exclude .git and other patterns",
|
name: "exclude .git and other patterns",
|
||||||
exclude: []string{"*.log", "temp/"},
|
exclude: []string{"*.log", "temp/"},
|
||||||
del: false,
|
del: false,
|
||||||
|
debug: false,
|
||||||
src: "/path/to/src",
|
src: "/path/to/src",
|
||||||
dest: "/path/to/dest",
|
dest: "/path/to/dest",
|
||||||
want: []string{
|
want: []string{
|
||||||
@ -30,15 +32,25 @@ func TestSyncDirectories(t *testing.T) {
|
|||||||
name: "delete enabled",
|
name: "delete enabled",
|
||||||
exclude: []string{},
|
exclude: []string{},
|
||||||
del: true,
|
del: true,
|
||||||
|
debug: false,
|
||||||
src: "/path/to/src",
|
src: "/path/to/src",
|
||||||
dest: "/path/to/dest",
|
dest: "/path/to/dest",
|
||||||
want: []string{"rsync", "-r", "--exclude", ".git", "--delete", ".", "/path/to/dest"},
|
want: []string{"rsync", "-r", "--exclude", ".git", "--delete", ".", "/path/to/dest"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "debug output enabled",
|
||||||
|
exclude: []string{},
|
||||||
|
del: false,
|
||||||
|
debug: true,
|
||||||
|
src: "/path/to/src",
|
||||||
|
dest: "/path/to/dest",
|
||||||
|
want: []string{"rsync", "-r", "--exclude", ".git", "--stats", ".", "/path/to/dest"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
cmd := SyncDirectories(tt.exclude, tt.del, tt.src, tt.dest)
|
cmd := SyncDirectories(tt.exclude, tt.del, tt.src, tt.dest, tt.debug)
|
||||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||||
assert.Equal(t, tt.src, cmd.Cmd.Dir)
|
assert.Equal(t, tt.src, cmd.Cmd.Dir)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user