0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-06-02 18:29:41 +02:00
wp-git-action/git/commit.go

58 lines
1.0 KiB
Go
Raw Normal View History

2022-11-27 14:33:39 +01:00
package git
2019-06-07 12:32:16 +02:00
import (
"os"
2024-05-06 22:43:56 +02:00
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
2019-06-07 12:32:16 +02:00
)
// Add updates the index to match the working tree.
func (r *Repository) Add() *plugin_exec.Cmd {
cmd := plugin_exec.Command(gitBin, "add", "--all")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
2024-05-06 20:29:57 +02:00
cmd.Dir = r.WorkDir
2019-06-07 12:32:16 +02:00
2024-05-06 22:43:56 +02:00
return cmd
2019-06-07 12:32:16 +02:00
}
// IsCleanTree returns non-zero if diff between index and local repository.
func (r *Repository) IsCleanTree() *plugin_exec.Cmd {
args := []string{
"diff-index",
"--quiet",
"HEAD",
"--ignore-submodules",
2024-05-06 22:43:56 +02:00
}
cmd := plugin_exec.Command(gitBin, args...)
2024-05-06 20:29:57 +02:00
cmd.Dir = r.WorkDir
cmd.Trace = false
2019-06-07 12:32:16 +02:00
2024-05-06 22:43:56 +02:00
return cmd
2019-06-07 12:32:16 +02:00
}
2024-05-06 20:29:57 +02:00
// Commit creates a new commit with the specified commit message.
func (r *Repository) Commit() *plugin_exec.Cmd {
args := []string{
2019-06-07 12:32:16 +02:00
"commit",
"-m",
2024-05-06 20:29:57 +02:00
r.CommitMsg,
}
2024-05-06 20:29:57 +02:00
if r.EmptyCommit {
args = append(args, "--allow-empty")
2019-06-07 12:32:16 +02:00
}
2024-05-06 20:29:57 +02:00
if r.NoVerify {
args = append(args, "--no-verify")
}
cmd := plugin_exec.Command(gitBin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
2024-05-06 20:29:57 +02:00
cmd.Dir = r.WorkDir
2019-06-07 12:32:16 +02:00
2024-05-06 22:43:56 +02:00
return cmd
2019-06-07 12:32:16 +02:00
}