DefaultWorkspaceFolder returns the default workspace folder for a given repository URL.
(workspacesFolder, repoURL string)
| 15 | // DefaultWorkspaceFolder returns the default workspace folder |
| 16 | // for a given repository URL. |
| 17 | func DefaultWorkspaceFolder(workspacesFolder, repoURL string) string { |
| 18 | // emptyWorkspaceDir is the path to a workspace that has |
| 19 | // nothing going on... it's empty! |
| 20 | emptyWorkspaceDir := workspacesFolder + "/empty" |
| 21 | |
| 22 | if repoURL == "" { |
| 23 | return emptyWorkspaceDir |
| 24 | } |
| 25 | parsed, err := ebutil.ParseRepoURL(repoURL) |
| 26 | if err != nil { |
| 27 | return emptyWorkspaceDir |
| 28 | } |
| 29 | repo := path.Base(parsed.Path) |
| 30 | // Giturls parsing never actually fails since ParseLocal never |
| 31 | // errors and places the entire URL in the Path field. This check |
| 32 | // ensures it's at least a Unix path containing forwardslash. |
| 33 | if repo == repoURL || repo == "/" || repo == "." || repo == "" { |
| 34 | return emptyWorkspaceDir |
| 35 | } |
| 36 | repo = strings.TrimSuffix(repo, ".git") |
| 37 | return fmt.Sprintf("%s/%s", workspacesFolder, repo) |
| 38 | } |
| 39 | |
| 40 | func (o *Options) SetDefaults() { |
| 41 | // Temporarily removed these from the default settings to prevent conflicts |