0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-10 04:00:39 +00:00
wp-git-clone/git/config.go

71 lines
1.3 KiB
Go
Raw Normal View History

2023-12-22 23:59:23 +00:00
package git
import (
"fmt"
"strconv"
"github.com/thegeeklab/wp-plugin-go/v2/types"
2023-12-22 23:59:23 +00:00
"golang.org/x/sys/execabs"
)
// ConfigSSLVerify disables globally the git ssl verification.
func (r *Repository) ConfigSSLVerify(skipVerify bool) *types.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"config",
"--global",
2023-12-22 23:59:23 +00:00
"http.sslVerify",
strconv.FormatBool(!skipVerify),
2023-12-22 23:59:23 +00:00
}
return &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
2023-12-22 23:59:23 +00:00
}
// ConfigSafeDirectory disables globally the git ssl verification.
func (r *Repository) ConfigSafeDirectory() *types.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"config",
"--global",
2023-12-22 23:59:23 +00:00
"--replace-all",
"safe.directory",
r.SafeDirectory,
2023-12-22 23:59:23 +00:00
}
return &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
2023-12-22 23:59:23 +00:00
}
// ConfigRemapSubmodule returns a git command that, when executed configures git to
// remap submodule urls.
func (r *Repository) ConfigRemapSubmodule(name, url string) *types.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"config",
"--global",
2023-12-22 23:59:23 +00:00
fmt.Sprintf("submodule.%s.url", name),
url,
}
return &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
2023-12-22 23:59:23 +00:00
}
// ConfigSSHCommand sets custom SSH key.
func (r *Repository) ConfigSSHCommand(sshKey string) *types.Cmd {
2023-12-22 23:59:23 +00:00
args := []string{
"config",
"--global",
2023-12-22 23:59:23 +00:00
"core.sshCommand",
"ssh -i " + sshKey,
}
cmd := &types.Cmd{
Cmd: execabs.Command(gitBin, args...),
}
cmd.SetTrace(false)
return cmd
2023-12-22 23:59:23 +00:00
}