0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-09-20 01:12:47 +02:00
wp-git-action/git/commit.go

97 lines
1.5 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 (
"github.com/thegeeklab/wp-plugin-go/v2/types"
"golang.org/x/sys/execabs"
2019-06-07 12:32:16 +02:00
)
// ForceAdd forces the addition of all dirty files.
func ForceAdd(repo Repository) *types.Cmd {
cmd := execabs.Command(
gitBin,
2019-06-07 12:32:16 +02:00
"add",
"--all",
"--force",
)
cmd.Dir = repo.WorkDir
2019-06-07 12:32:16 +02:00
return &types.Cmd{
Cmd: cmd,
}
2019-06-07 12:32:16 +02:00
}
// Add updates the index to match the working tree.
func Add(repo Repository) *types.Cmd {
cmd := execabs.Command(
gitBin,
2019-06-07 12:32:16 +02:00
"add",
)
cmd.Dir = repo.WorkDir
if repo.Add != "" {
cmd.Args = append(cmd.Args, repo.Add)
} else {
cmd.Args = append(cmd.Args, "--all")
}
2019-06-07 12:32:16 +02:00
return &types.Cmd{
Cmd: cmd,
}
2019-06-07 12:32:16 +02:00
}
// TestCleanTree returns non-zero if diff between index and local repository.
func IsCleanTree(repo Repository) *types.Cmd {
cmd := execabs.Command(
gitBin,
2019-06-07 12:32:16 +02:00
"diff-index",
"--quiet",
"HEAD",
"--ignore-submodules",
)
cmd.Dir = repo.WorkDir
2019-06-07 12:32:16 +02:00
return &types.Cmd{
Cmd: cmd,
}
2019-06-07 12:32:16 +02:00
}
// EmptyCommit simply create an empty commit.
func EmptyCommit(repo Repository) *types.Cmd {
args := []string{
2019-06-07 12:32:16 +02:00
"commit",
"--allow-empty",
"-m",
repo.CommitMsg,
}
cmd := execabs.Command(gitBin, args...)
cmd.Dir = repo.WorkDir
2019-06-07 12:32:16 +02:00
if repo.NoVerify {
cmd.Args = append(cmd.Args, "--no-verify")
2019-06-07 12:32:16 +02:00
}
return &types.Cmd{
Cmd: cmd,
}
2019-06-07 12:32:16 +02:00
}
func Commit(repo Repository) *types.Cmd {
args := []string{
2019-06-07 12:32:16 +02:00
"commit",
"-m",
repo.CommitMsg,
}
cmd := execabs.Command(gitBin, args...)
cmd.Dir = repo.WorkDir
2019-06-07 12:32:16 +02:00
if repo.NoVerify {
cmd.Args = append(cmd.Args, "--no-verify")
2019-06-07 12:32:16 +02:00
}
return &types.Cmd{
Cmd: cmd,
}
2019-06-07 12:32:16 +02:00
}