diff --git a/git/config.go b/git/config.go index 90a6400..9ccbc36 100644 --- a/git/config.go +++ b/git/config.go @@ -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 diff --git a/plugin/impl.go b/plugin/impl.go index 2eafd61..5b8b65d 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -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), ), ) diff --git a/plugin/rsync.go b/plugin/rsync.go index b6170a0..820e5fb 100644 --- a/plugin/rsync.go +++ b/plugin/rsync.go @@ -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, ".", diff --git a/plugin/rsync_test.go b/plugin/rsync_test.go index 04563c3..88cdf11 100644 --- a/plugin/rsync_test.go +++ b/plugin/rsync_test.go @@ -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) })