2023-12-22 23:59:23 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2024-05-17 19:50:05 +00:00
|
|
|
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
2023-12-22 23:59:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ConfigSSLVerify disables globally the git ssl verification.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) ConfigSSLVerify(skipVerify bool) *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"config",
|
2023-12-23 15:12:56 +00:00
|
|
|
"--global",
|
2023-12-22 23:59:23 +00:00
|
|
|
"http.sslVerify",
|
2024-05-06 18:30:18 +00:00
|
|
|
strconv.FormatBool(!skipVerify),
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Trace = false
|
|
|
|
|
|
|
|
return cmd
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigSafeDirectory disables globally the git ssl verification.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) ConfigSafeDirectory() *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"config",
|
2023-12-23 15:12:56 +00:00
|
|
|
"--global",
|
2023-12-22 23:59:23 +00:00
|
|
|
"--replace-all",
|
|
|
|
"safe.directory",
|
2024-05-06 18:30:18 +00:00
|
|
|
r.SafeDirectory,
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Trace = false
|
|
|
|
|
|
|
|
return cmd
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigRemapSubmodule returns a git command that, when executed configures git to
|
|
|
|
// remap submodule urls.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) ConfigRemapSubmodule(name, url string) *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"config",
|
2023-12-23 15:12:56 +00:00
|
|
|
"--global",
|
2023-12-22 23:59:23 +00:00
|
|
|
fmt.Sprintf("submodule.%s.url", name),
|
|
|
|
url,
|
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Trace = false
|
|
|
|
|
|
|
|
return cmd
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigSSHCommand sets custom SSH key.
|
2024-05-17 19:50:05 +00:00
|
|
|
func (r *Repository) ConfigSSHCommand(sshKey string) *plugin_exec.Cmd {
|
2023-12-22 23:59:23 +00:00
|
|
|
args := []string{
|
|
|
|
"config",
|
2023-12-23 15:12:56 +00:00
|
|
|
"--global",
|
2023-12-22 23:59:23 +00:00
|
|
|
"core.sshCommand",
|
|
|
|
"ssh -i " + sshKey,
|
|
|
|
}
|
|
|
|
|
2024-05-17 19:50:05 +00:00
|
|
|
cmd := plugin_exec.Command(gitBin, args...)
|
|
|
|
cmd.Trace = false
|
2024-05-06 20:45:33 +00:00
|
|
|
|
|
|
|
return cmd
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|