mirror of
https://github.com/thegeeklab/wp-git-action.git
synced 2024-11-24 22:50:39 +00:00
fix: fix command exec order (#115)
This commit is contained in:
parent
dbc0ea945b
commit
5930a2ad75
16
git/clone.go
16
git/clone.go
@ -15,12 +15,12 @@ func (r *Repository) FetchSource() *types.Cmd {
|
|||||||
fmt.Sprintf("+%s:", r.Branch),
|
fmt.Sprintf("+%s:", r.Branch),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckoutHead handles branch checkout.
|
// CheckoutHead handles branch checkout.
|
||||||
@ -31,10 +31,10 @@ func (r *Repository) CheckoutHead() *types.Cmd {
|
|||||||
r.Branch,
|
r.Branch,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,52 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
||||||
"golang.org/x/sys/execabs"
|
"golang.org/x/sys/execabs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add updates the index to match the working tree.
|
// Add updates the index to match the working tree.
|
||||||
func (r *Repository) Add() *types.Cmd {
|
func (r *Repository) Add() *types.Cmd {
|
||||||
cmd := execabs.Command(
|
cmd := &types.Cmd{
|
||||||
gitBin,
|
Cmd: execabs.Command(
|
||||||
"add",
|
gitBin,
|
||||||
"--all",
|
"add",
|
||||||
)
|
"--all",
|
||||||
|
),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCleanTree returns non-zero if diff between index and local repository.
|
// TestCleanTree returns non-zero if diff between index and local repository.
|
||||||
func (r *Repository) IsCleanTree() *types.Cmd {
|
func (r *Repository) IsCleanTree() *types.Cmd {
|
||||||
cmd := execabs.Command(
|
cmd := &types.Cmd{
|
||||||
gitBin,
|
Cmd: execabs.Command(
|
||||||
"diff-index",
|
gitBin,
|
||||||
"--quiet",
|
"diff-index",
|
||||||
"HEAD",
|
"--quiet",
|
||||||
"--ignore-submodules",
|
"HEAD",
|
||||||
)
|
"--ignore-submodules",
|
||||||
cmd.Dir = r.WorkDir
|
),
|
||||||
|
|
||||||
return &types.Cmd{
|
|
||||||
Cmd: cmd,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Dir = r.WorkDir
|
||||||
|
cmd.Stdout = io.Discard
|
||||||
|
cmd.Stderr = io.Discard
|
||||||
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit creates a new commit with the specified commit message.
|
// Commit creates a new commit with the specified commit message.
|
||||||
func (r *Repository) Commit() *types.Cmd {
|
func (r *Repository) Commit() *types.Cmd {
|
||||||
|
if err := r.IsCleanTree().Run(); err == nil && !r.EmptyCommit {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"commit",
|
"commit",
|
||||||
"-m",
|
"-m",
|
||||||
@ -51,10 +61,10 @@ func (r *Repository) Commit() *types.Cmd {
|
|||||||
args = append(args, "--no-verify")
|
args = append(args, "--no-verify")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@ func (r *Repository) ConfigAutocorrect() *types.Cmd {
|
|||||||
r.Autocorrect,
|
r.Autocorrect,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigUserEmail sets the global git author email.
|
// ConfigUserEmail sets the global git author email.
|
||||||
@ -34,12 +34,12 @@ func (r *Repository) ConfigUserEmail() *types.Cmd {
|
|||||||
r.Author.Email,
|
r.Author.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigUserName configures the user.name git config setting for the given repository.
|
// ConfigUserName configures the user.name git config setting for the given repository.
|
||||||
@ -51,12 +51,12 @@ func (r *Repository) ConfigUserName() *types.Cmd {
|
|||||||
r.Author.Name,
|
r.Author.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigSSLVerify configures the http.sslVerify git config setting for the given repository.
|
// ConfigSSLVerify configures the http.sslVerify git config setting for the given repository.
|
||||||
@ -68,12 +68,12 @@ func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd {
|
|||||||
strconv.FormatBool(!skipVerify),
|
strconv.FormatBool(!skipVerify),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigSSHCommand sets custom SSH key.
|
// ConfigSSHCommand sets custom SSH key.
|
||||||
@ -85,7 +85,10 @@ func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd {
|
|||||||
"ssh -i " + sshKey,
|
"ssh -i " + sshKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Cmd{
|
cmd := &types.Cmd{
|
||||||
Cmd: execabs.Command(gitBin, args...),
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
|
cmd.SetTrace(false)
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@ func (r *Repository) Init() *types.Cmd {
|
|||||||
r.Branch,
|
r.Branch,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,12 @@ func (r *Repository) RemoteRemove() *types.Cmd {
|
|||||||
r.RemoteName,
|
r.RemoteName,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteAdd adds an additional remote to a git repo.
|
// RemoteAdd adds an additional remote to a git repo.
|
||||||
@ -32,12 +32,12 @@ func (r *Repository) RemoteAdd() *types.Cmd {
|
|||||||
r.RemoteURL,
|
r.RemoteURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemotePush pushs the changes from the local head to a remote branch.
|
// RemotePush pushs the changes from the local head to a remote branch.
|
||||||
@ -48,18 +48,18 @@ func (r *Repository) RemotePush() *types.Cmd {
|
|||||||
fmt.Sprintf("HEAD:%s", r.Branch),
|
fmt.Sprintf("HEAD:%s", r.Branch),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := execabs.Command(gitBin, args...)
|
|
||||||
cmd.Dir = r.WorkDir
|
|
||||||
|
|
||||||
if r.ForcePush {
|
if r.ForcePush {
|
||||||
cmd.Args = append(cmd.Args, "--force")
|
args = append(args, "--force")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.PushFollowTags {
|
if r.PushFollowTags {
|
||||||
cmd.Args = append(cmd.Args, "--follow-tags")
|
args = append(args, "--follow-tags")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Cmd{
|
cmd := &types.Cmd{
|
||||||
Cmd: cmd,
|
Cmd: execabs.Command(gitBin, args...),
|
||||||
}
|
}
|
||||||
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,16 @@ import (
|
|||||||
|
|
||||||
// Status returns a command that runs `git status --porcelain` for the given repository.
|
// Status returns a command that runs `git status --porcelain` for the given repository.
|
||||||
func (r *Repository) Status() *types.Cmd {
|
func (r *Repository) Status() *types.Cmd {
|
||||||
cmd := execabs.Command(
|
cmd := &types.Cmd{
|
||||||
gitBin,
|
Cmd: execabs.Command(
|
||||||
"status",
|
gitBin,
|
||||||
"--porcelain",
|
"status",
|
||||||
)
|
"--porcelain",
|
||||||
|
),
|
||||||
|
}
|
||||||
cmd.Dir = r.WorkDir
|
cmd.Dir = r.WorkDir
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDirty checks if the given repository has any uncommitted changes.
|
// IsDirty checks if the given repository has any uncommitted changes.
|
||||||
|
@ -137,6 +137,7 @@ func (p *Plugin) Execute() error {
|
|||||||
if err := os.MkdirAll(p.Settings.Repo.WorkDir, os.ModePerm); err != nil {
|
if err := os.MkdirAll(p.Settings.Repo.WorkDir, os.ModePerm); err != nil {
|
||||||
return fmt.Errorf("failed to create working directory: %w", err)
|
return fmt.Errorf("failed to create working directory: %w", err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(p.Settings.Repo.WorkDir)
|
||||||
|
|
||||||
p.Settings.Repo.IsEmpty, err = file.IsDirEmpty(p.Settings.Repo.WorkDir)
|
p.Settings.Repo.IsEmpty, err = file.IsDirEmpty(p.Settings.Repo.WorkDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -215,10 +216,7 @@ func (p *Plugin) handleCommit() []*types.Cmd {
|
|||||||
var cmds []*types.Cmd
|
var cmds []*types.Cmd
|
||||||
|
|
||||||
cmds = append(cmds, p.Settings.Repo.Add())
|
cmds = append(cmds, p.Settings.Repo.Add())
|
||||||
|
cmds = append(cmds, p.Settings.Repo.Commit())
|
||||||
if err := p.Settings.Repo.IsCleanTree().Run(); err != nil || p.Settings.Repo.EmptyCommit {
|
|
||||||
cmds = append(cmds, p.Settings.Repo.Commit())
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmds
|
return cmds
|
||||||
}
|
}
|
||||||
@ -232,8 +230,6 @@ 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
|
||||||
|
|
||||||
defer os.RemoveAll(p.Settings.Repo.WorkDir)
|
|
||||||
|
|
||||||
ccmd, err := p.handleClone()
|
ccmd, err := p.handleClone()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmds, err
|
return cmds, err
|
||||||
|
@ -34,10 +34,10 @@ func SyncDirectories(exclude []string, del bool, src, dest string) *types.Cmd {
|
|||||||
dest,
|
dest,
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd := execabs.Command("rsync", args...)
|
cmd := &types.Cmd{
|
||||||
|
Cmd: execabs.Command("rsync", args...),
|
||||||
|
}
|
||||||
cmd.Dir = src
|
cmd.Dir = src
|
||||||
|
|
||||||
return &types.Cmd{
|
return cmd
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user