0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-24 12:40:39 +00:00

fix: disable cmd trace for git config commands (#118)

This commit is contained in:
Robert Kaussow 2024-05-14 10:19:04 +02:00 committed by GitHub
parent c97278aa5a
commit c1402d7c33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 2 deletions

View File

@ -21,6 +21,7 @@ func (r *Repository) ConfigAutocorrect() *types.Cmd {
Cmd: execabs.Command(gitBin, args...),
}
cmd.Dir = r.WorkDir
cmd.SetTrace(false)
return cmd
}
@ -38,6 +39,7 @@ func (r *Repository) ConfigUserEmail() *types.Cmd {
Cmd: execabs.Command(gitBin, args...),
}
cmd.Dir = r.WorkDir
cmd.SetTrace(false)
return cmd
}
@ -55,6 +57,7 @@ func (r *Repository) ConfigUserName() *types.Cmd {
Cmd: execabs.Command(gitBin, args...),
}
cmd.Dir = r.WorkDir
cmd.SetTrace(false)
return cmd
}
@ -72,6 +75,7 @@ func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd {
Cmd: execabs.Command(gitBin, args...),
}
cmd.Dir = r.WorkDir
cmd.SetTrace(false)
return cmd
}
@ -88,6 +92,7 @@ func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd {
cmd := &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
cmd.Dir = r.WorkDir
cmd.SetTrace(false)
return cmd

View File

@ -7,6 +7,8 @@ import (
"os"
"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/types"
"github.com/thegeeklab/wp-plugin-go/v2/util"
@ -163,6 +165,8 @@ func (p *Plugin) Execute() error {
action := GitAction(actionStr)
switch action {
case GitActionClone:
log.Debug().Msg("Compose action cmd: clone")
cmds, err := p.handleClone()
if err != nil {
return err
@ -170,10 +174,16 @@ func (p *Plugin) Execute() error {
batchCmd = append(batchCmd, cmds...)
case GitActionCommit:
log.Debug().Msg("Compose action cmd: commit")
batchCmd = append(batchCmd, p.handleCommit()...)
case GitActionPush:
log.Debug().Msg("Compose action cmd: push")
batchCmd = append(batchCmd, p.handlePush()...)
case GitActionPages:
log.Debug().Msg("Compose action cmd: pages")
cmds, err := p.handlePages()
if err != nil {
return err
@ -234,6 +244,11 @@ func (p *Plugin) handlePush() []*types.Cmd {
func (p *Plugin) handlePages() ([]*types.Cmd, error) {
var cmds []*types.Cmd
log.Debug().
Str("src", p.Settings.Pages.Directory).
Str("dest", p.Settings.Repo.WorkDir).
Msg("handlePages")
ccmd, err := p.handleClone()
if err != nil {
return cmds, err
@ -246,6 +261,7 @@ func (p *Plugin) handlePages() ([]*types.Cmd, error) {
p.Settings.Pages.Delete,
p.Settings.Pages.Directory,
p.Settings.Repo.WorkDir,
(zerolog.GlobalLevel() == zerolog.DebugLevel),
),
)

View File

@ -6,7 +6,7 @@ import (
"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{
"-r",
"--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,
".",

View File

@ -11,6 +11,7 @@ func TestSyncDirectories(t *testing.T) {
name string
exclude []string
del bool
debug bool
src string
dest string
want []string
@ -19,6 +20,7 @@ func TestSyncDirectories(t *testing.T) {
name: "exclude .git and other patterns",
exclude: []string{"*.log", "temp/"},
del: false,
debug: false,
src: "/path/to/src",
dest: "/path/to/dest",
want: []string{
@ -30,15 +32,25 @@ func TestSyncDirectories(t *testing.T) {
name: "delete enabled",
exclude: []string{},
del: true,
debug: false,
src: "/path/to/src",
dest: "/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 {
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.src, cmd.Cmd.Dir)
})