2022-11-27 13:33:39 +00:00
|
|
|
package git
|
2019-06-07 10:32:16 +00:00
|
|
|
|
|
|
|
import (
|
2024-05-05 20:14:55 +00:00
|
|
|
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
2023-02-08 09:16:10 +00:00
|
|
|
"golang.org/x/sys/execabs"
|
2019-06-07 10:32:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Add updates the index to match the working tree.
|
2024-05-06 18:29:57 +00:00
|
|
|
func (r *Repository) Add() *types.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
cmd := execabs.Command(
|
|
|
|
gitBin,
|
2019-06-07 10:32:16 +00:00
|
|
|
"add",
|
2024-05-06 18:29:57 +00:00
|
|
|
"--all",
|
2022-12-02 21:21:35 +00:00
|
|
|
)
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd.Dir = r.WorkDir
|
2019-06-07 10:32:16 +00:00
|
|
|
|
2024-05-05 20:14:55 +00:00
|
|
|
return &types.Cmd{
|
|
|
|
Cmd: cmd,
|
|
|
|
}
|
2019-06-07 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
2023-02-08 09:16:10 +00:00
|
|
|
// TestCleanTree returns non-zero if diff between index and local repository.
|
2024-05-06 18:29:57 +00:00
|
|
|
func (r *Repository) IsCleanTree() *types.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
cmd := execabs.Command(
|
|
|
|
gitBin,
|
2019-06-07 10:32:16 +00:00
|
|
|
"diff-index",
|
|
|
|
"--quiet",
|
|
|
|
"HEAD",
|
2022-12-02 21:21:35 +00:00
|
|
|
"--ignore-submodules",
|
|
|
|
)
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd.Dir = r.WorkDir
|
2019-06-07 10:32:16 +00:00
|
|
|
|
2024-05-05 20:14:55 +00:00
|
|
|
return &types.Cmd{
|
|
|
|
Cmd: cmd,
|
|
|
|
}
|
2019-06-07 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 18:29:57 +00:00
|
|
|
// Commit creates a new commit with the specified commit message.
|
|
|
|
func (r *Repository) Commit() *types.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2019-06-07 10:32:16 +00:00
|
|
|
"commit",
|
|
|
|
"-m",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.CommitMsg,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 18:29:57 +00:00
|
|
|
if r.EmptyCommit {
|
|
|
|
args = append(args, "--allow-empty")
|
2019-06-07 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 18:29:57 +00:00
|
|
|
if r.NoVerify {
|
|
|
|
args = append(args, "--no-verify")
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 20:14:55 +00:00
|
|
|
cmd := execabs.Command(gitBin, args...)
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd.Dir = r.WorkDir
|
2019-06-07 10:32:16 +00:00
|
|
|
|
2024-05-05 20:14:55 +00:00
|
|
|
return &types.Cmd{
|
|
|
|
Cmd: cmd,
|
|
|
|
}
|
2019-06-07 10:32:16 +00:00
|
|
|
}
|