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

Function GitCloneTemplateRepo4Remote

cli/cmd/init/initVM.go:111–209  ·  view source on GitHub ↗

在服务器上使用git下载制定的template文件,完成后删除.git文件

(sshRemote common.SSHRemote, projectDir string, templateGitCloneUrl string, baseType string, subType string)

Source from the content-addressed store, hash-verified

109
110// 在服务器上使用git下载制定的template文件,完成后删除.git文件
111func GitCloneTemplateRepo4Remote(sshRemote common.SSHRemote, projectDir string, templateGitCloneUrl string, baseType string, subType string) error {
112
113 // git
114 tempDirPath := common.FilePahtJoin4Linux("~", ".ide", "template")
115 command := fmt.Sprintf(`
116cd %v
117[[ -d .git ]] && (git checkout . && git clean -xdf && git pull) || git clone %v %v
118`, tempDirPath, templateGitCloneUrl, tempDirPath)
119 err := sshRemote.ExecSSHCommandRealTime(command)
120 if err != nil {
121 common.SmartIDELog.Importance(err.Error())
122 if strings.Contains(err.Error(), "You have not concluded your merge") {
123 common.SmartIDELog.Debug("re-pull")
124 command = fmt.Sprintf(`cd %v
125git fetch --all && git reset --hard origin/master && git fetch && git pull`,
126 tempDirPath)
127 err = sshRemote.ExecSSHCommandRealTime(command)
128 }
129
130 return err
131
132 }
133
134 templatesPath := common.FilePahtJoin4Linux("~", ".ide", "template", "templates.json")
135 templateContent := sshRemote.GetContent(templatesPath)
136
137 var templateTypes []NewTypeBO
138
139 err = json.Unmarshal([]byte(templateContent), &templateTypes)
140 if err != nil {
141 return nil
142 }
143
144 selectedTemplateTypeName := ""
145
146 selectedTemplateSubTypeName := ""
147 for _, currentTemplateType := range templateTypes {
148 if currentTemplateType.TypeName == baseType {
149 selectedTemplateTypeName = baseType
150 }
151 for _, currentTemplateTypeSubType := range currentTemplateType.SubTypes {
152 if currentTemplateTypeSubType.Name == subType {
153 selectedTemplateSubTypeName = currentTemplateTypeSubType.Name
154 }
155 }
156 }
157
158 if selectedTemplateTypeName == "" || selectedTemplateSubTypeName == "" {
159 common.SmartIDELog.InfoF(i18nInstance.Init.Info_noexist_cmdtemplate)
160
161 fmt.Println(i18nInstance.Init.Info_available_templates)
162 PrintTemplates(templateTypes) // 打印支持的模版列表
163
164 fmt.Print(i18nInstance.Init.Info_choose_templatetype)
165 var indexChar string
166 fmt.Scanln(&indexChar)
167 index, err := strconv.Atoi(indexChar)
168 if err != nil {

Callers 1

VmInitFunction · 0.85

Calls 8

PrintTemplatesFunction · 0.85
ImportanceMethod · 0.80
DebugMethod · 0.80
GetContentMethod · 0.80
InfoFMethod · 0.80
ErrorMethod · 0.45
JoinMethod · 0.45

Tested by

no test coverage detected