0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-24 22:50:39 +00:00
wp-git-action/git/commit.go

100 lines
1.6 KiB
Go
Raw Normal View History

2022-11-27 13:33:39 +00:00
package git
2019-06-07 10:32:16 +00:00
import (
"os"
"golang.org/x/sys/execabs"
2019-06-07 10:32:16 +00:00
)
// ForceAdd forces the addition of all dirty files.
func ForceAdd(repo Repository) *execabs.Cmd {
cmd := execabs.Command(
gitBin,
2019-06-07 10:32:16 +00:00
"add",
"--all",
"--force",
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 10:32:16 +00:00
return cmd
}
// Add updates the index to match the working tree.
func Add(repo Repository) *execabs.Cmd {
cmd := execabs.Command(
gitBin,
2019-06-07 10:32:16 +00:00
"add",
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
if repo.Add != "" {
cmd.Args = append(cmd.Args, repo.Add)
} else {
cmd.Args = append(cmd.Args, "--all")
}
2019-06-07 10:32:16 +00:00
return cmd
}
// TestCleanTree returns non-zero if diff between index and local repository.
func TestCleanTree(repo Repository) *execabs.Cmd {
cmd := execabs.Command(
gitBin,
2019-06-07 10:32:16 +00:00
"diff-index",
"--quiet",
"HEAD",
"--ignore-submodules",
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 10:32:16 +00:00
return cmd
}
// EmptyCommit simply create an empty commit.
func EmptyCommit(repo Repository) *execabs.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"commit",
"--allow-empty",
"-m",
repo.CommitMsg,
}
cmd := execabs.Command(
gitBin,
args...,
2019-06-07 10:32:16 +00:00
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 10:32:16 +00:00
if repo.NoVerify {
cmd.Args = append(cmd.Args, "--no-verify")
2019-06-07 10:32:16 +00:00
}
return cmd
}
// ForceCommit commits every change while skipping CI.
func ForceCommit(repo Repository) *execabs.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"commit",
"-m",
repo.CommitMsg,
}
cmd := execabs.Command(
gitBin,
args...,
2019-06-07 10:32:16 +00:00
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
2019-06-07 10:32:16 +00:00
if repo.NoVerify {
cmd.Args = append(cmd.Args, "--no-verify")
2019-06-07 10:32:16 +00:00
}
return cmd
}