2022-11-27 13:33:39 +00:00
|
|
|
package git
|
2019-06-07 10:32:16 +00:00
|
|
|
|
|
|
|
import (
|
2022-11-29 09:40:42 +00:00
|
|
|
"strconv"
|
2023-02-08 09:16:10 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2024-05-05 20:14:55 +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 {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2022-12-02 21:21:35 +00:00
|
|
|
"config",
|
|
|
|
"--local",
|
|
|
|
"help.autocorrect",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.Autocorrect,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
2022-12-02 21:21:35 +00:00
|
|
|
|
2024-05-06 20:43:56 +00:00
|
|
|
return cmd
|
2022-12-02 21:21:35 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 20:14:55 +00:00
|
|
|
// ConfigUserEmail sets the global git author email.
|
2024-05-06 18:29:57 +00:00
|
|
|
func (r *Repository) ConfigUserEmail() *types.Cmd {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2019-06-07 10:32:16 +00:00
|
|
|
"config",
|
2022-11-29 09:40:42 +00:00
|
|
|
"--local",
|
2019-06-07 10:32:16 +00:00
|
|
|
"user.email",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.Author.Email,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-05-05 20:14:55 +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 {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2019-06-07 10:32:16 +00:00
|
|
|
"config",
|
2022-11-29 09:40:42 +00:00
|
|
|
"--local",
|
2019-06-07 10:32:16 +00:00
|
|
|
"user.name",
|
2024-05-06 18:29:57 +00:00
|
|
|
r.Author.Name,
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2022-11-29 09:40:42 +00:00
|
|
|
|
2024-05-05 20:14:55 +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 {
|
2023-02-08 09:16:10 +00:00
|
|
|
args := []string{
|
2022-11-29 09:40:42 +00:00
|
|
|
"config",
|
|
|
|
"--local",
|
|
|
|
"http.sslVerify",
|
2024-05-05 20:14:55 +00:00
|
|
|
strconv.FormatBool(!skipVerify),
|
2023-02-08 09:16:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
2022-11-29 09:40:42 +00:00
|
|
|
|
2024-05-06 20:43:56 +00:00
|
|
|
return cmd
|
2022-11-29 09:40:42 +00:00
|
|
|
}
|
2024-05-06 20:17:45 +00:00
|
|
|
|
|
|
|
// 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{
|
2024-05-06 20:17:45 +00:00
|
|
|
Cmd: execabs.Command(gitBin, args...),
|
|
|
|
}
|
2024-05-06 20:43:56 +00:00
|
|
|
cmd.SetTrace(false)
|
|
|
|
|
|
|
|
return cmd
|
2024-05-06 20:17:45 +00:00
|
|
|
}
|