0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-09 17:10:41 +00:00
wp-git-action/git/config.go

95 lines
1.8 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 (
"strconv"
"github.com/thegeeklab/wp-plugin-go/v2/types"
"golang.org/x/sys/execabs"
2019-06-07 10:32:16 +00:00
)
// ConfigAutocorrect sets the local git autocorrect configuration for the given repository.
// The autocorrect setting determines how git handles minor typos in commands.
2024-05-06 18:29:57 +00:00
func (r *Repository) ConfigAutocorrect() *types.Cmd {
args := []string{
"config",
"--local",
"help.autocorrect",
2024-05-06 18:29:57 +00:00
r.Autocorrect,
}
2024-05-06 20:43:56 +00:00
cmd := &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
2024-05-06 18:29:57 +00:00
cmd.Dir = r.WorkDir
2024-05-06 20:43:56 +00:00
return cmd
}
// ConfigUserEmail sets the global git author email.
2024-05-06 18:29:57 +00:00
func (r *Repository) ConfigUserEmail() *types.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"config",
"--local",
2019-06-07 10:32:16 +00:00
"user.email",
2024-05-06 18:29:57 +00:00
r.Author.Email,
}
2024-05-06 20:43:56 +00:00
cmd := &types.Cmd{
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-06 20:43:56 +00:00
return cmd
2019-06-07 10:32:16 +00:00
}
// ConfigUserName configures the user.name git config setting for the given repository.
2024-05-06 18:29:57 +00:00
func (r *Repository) ConfigUserName() *types.Cmd {
args := []string{
2019-06-07 10:32:16 +00:00
"config",
"--local",
2019-06-07 10:32:16 +00:00
"user.name",
2024-05-06 18:29:57 +00:00
r.Author.Name,
}
2024-05-06 20:43:56 +00:00
cmd := &types.Cmd{
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-06 20:43:56 +00:00
return cmd
2019-06-07 10:32:16 +00:00
}
// ConfigSSLVerify configures the http.sslVerify git config setting for the given repository.
2024-05-06 18:29:57 +00:00
func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd {
args := []string{
"config",
"--local",
"http.sslVerify",
strconv.FormatBool(!skipVerify),
}
2024-05-06 20:43:56 +00:00
cmd := &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
2024-05-06 18:29:57 +00:00
cmd.Dir = r.WorkDir
2024-05-06 20:43:56 +00:00
return cmd
}
// ConfigSSHCommand sets custom SSH key.
func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd {
args := []string{
"config",
"--local",
"core.sshCommand",
"ssh -i " + sshKey,
}
2024-05-06 20:43:56 +00:00
cmd := &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
2024-05-06 20:43:56 +00:00
cmd.SetTrace(false)
return cmd
}