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

Function loadGitInfo4Workspace

cli/cmd/common/workspace.go:453–481  ·  view source on GitHub ↗

从命令行中加载 git 相关信息

(workspaceInfo *workspace.WorkspaceInfo, cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

451
452// 从命令行中加载 git 相关信息
453func loadGitInfo4Workspace(workspaceInfo *workspace.WorkspaceInfo, cmd *cobra.Command, args []string) error {
454 if workspaceInfo.GitCloneRepoUrl == "" {
455 // 从args或flags中获取giturl,如 : smartide start https://github.com/idcf-boat-house/boathouse-calculator.git
456 workspaceInfo.GitCloneRepoUrl = getGitUrlFromArgs(cmd, args)
457 }
458
459 // 用户名密码
460 fflags := cmd.Flags()
461 gitUsername := getFlagValue(fflags, "gitusername")
462 gitPassword := getFlagValue(fflags, "gitpassword")
463 if gitPassword != "" && gitUsername == "" {
464 return errors.New("当参数 --gitpassword 不为空时,--gitusername 参数必须设置")
465 } else if gitPassword == "" && gitUsername != "" {
466 return errors.New("当参数 --gitusername 不为空时,--gitpassword 参数必须设置")
467 }
468 workspaceInfo.GitUserName = gitUsername
469 workspaceInfo.GitPassword = gitPassword
470
471 // 认证类型
472 if strings.Index(workspaceInfo.GitCloneRepoUrl, "git") == 0 {
473 workspaceInfo.GitRepoAuthType = workspace.GitRepoAuthType_SSH
474 } else if workspaceInfo.GitUserName != "" && workspaceInfo.GitPassword != "" {
475 workspaceInfo.GitRepoAuthType = workspace.GitRepoAuthType_Basic
476 } else {
477 workspaceInfo.GitRepoAuthType = workspace.GitRepoAuthType_Public
478 }
479
480 return nil
481}
482
483// 从文件夹中获取git repo url
484func getLocalGitRepoUrl(pwd string) (gitRemmoteUrl, pathName string, err error) {

Callers 1

GetWorkspaceFromCmdFunction · 0.85

Calls 2

getGitUrlFromArgsFunction · 0.85
getFlagValueFunction · 0.70

Tested by

no test coverage detected