MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / CopyLocalGitConfigToPod

Method CopyLocalGitConfigToPod

cli/pkg/k8s/k8sUtil.go:217–252  ·  view source on GitHub ↗

拷贝本地git config到pod

(pod coreV1.Pod, containerName string, runAsUser string)

Source from the content-addressed store, hash-verified

215
216// 拷贝本地git config到pod
217func (k *KubernetesUtil) CopyLocalGitConfigToPod(pod coreV1.Pod, containerName string, runAsUser string) error {
218 home, err := os.UserHomeDir()
219 if err != nil {
220 return err
221 }
222
223 cmd := exec.Command("git", "config", "--list")
224 cmd.Dir = home // 运行目录设置到home
225 bytes, err := cmd.CombinedOutput()
226 if err != nil {
227 return err
228 }
229 gitconfigs := "core.autocrlf=true\n"
230 gitconfigs = fmt.Sprintf("%s%s", gitconfigs, strings.ReplaceAll(string(bytes), "file:", ""))
231 for _, str := range strings.Split(gitconfigs, "\n") {
232 str = strings.TrimSpace(str)
233 if str == "" {
234 continue
235 }
236 var index = strings.Index(str, "=")
237 if index < 0 {
238 continue
239 }
240 var key = str[0:index]
241 var value = str[index+1:]
242 if strings.Contains(key, "user.name") || strings.Contains(key, "user.email") || strings.Contains(key, "core.autocrlf") {
243 gitConfigCmd := fmt.Sprintf(`git config --global --replace-all %v '%v'`, key, value)
244 err = k.ExecuteCommandRealtimeInPod(pod, containerName, gitConfigCmd, runAsUser)
245 if err != nil {
246 return err
247 }
248 }
249 }
250
251 return nil
252}
253
254// git clone
255func (k *KubernetesUtil) GitClone(pod coreV1.Pod,

Callers 1

execPodFunction · 0.80

Calls 2

CombinedOutputMethod · 0.80

Tested by

no test coverage detected