Skip to content

Commit 3b50a8f

Browse files
committed
fix: branch assignment
Signed-off-by: Toma Puljak <[email protected]>
1 parent 1f66e6a commit 3b50a8f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

pkg/cmd/workspace/create.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var CreateCmd = &cobra.Command{
8181
}
8282

8383
if len(args) == 0 {
84-
err = processPrompting(apiClient, &workspaceName, &projects, existingWorkspaceNames, ctx)
84+
err = processPrompting(ctx, apiClient, &workspaceName, &projects, existingWorkspaceNames)
8585
if err != nil {
8686
if common.IsCtrlCAbort(err) {
8787
return
@@ -90,7 +90,7 @@ var CreateCmd = &cobra.Command{
9090
}
9191
}
9292
} else {
93-
existingProjectConfigNames, err = processCmdArguments(args, apiClient, &projects, ctx)
93+
existingProjectConfigNames, err = processCmdArguments(ctx, args, apiClient, &projects)
9494
if err != nil {
9595
log.Fatal(err)
9696
}
@@ -278,7 +278,7 @@ func getTarget(targetList []apiclient.ProviderTarget, activeProfileName string)
278278
return target.GetTargetFromPrompt(targetList, activeProfileName, false)
279279
}
280280

281-
func processPrompting(apiClient *apiclient.APIClient, workspaceName *string, projects *[]apiclient.CreateProjectDTO, workspaceNames []string, ctx context.Context) error {
281+
func processPrompting(ctx context.Context, apiClient *apiclient.APIClient, workspaceName *string, projects *[]apiclient.CreateProjectDTO, workspaceNames []string) error {
282282
if workspace_util.CheckAnyProjectConfigurationFlagSet(projectConfigurationFlags) || (projectConfigurationFlags.Branches != nil && len(*projectConfigurationFlags.Branches) > 0) {
283283
return errors.New("please provide the repository URL in order to set up custom project details through the CLI")
284284
}
@@ -340,7 +340,7 @@ func processPrompting(apiClient *apiclient.APIClient, workspaceName *string, pro
340340
return nil
341341
}
342342

343-
func processCmdArguments(repoUrls []string, apiClient *apiclient.APIClient, projects *[]apiclient.CreateProjectDTO, ctx context.Context) ([]string, error) {
343+
func processCmdArguments(ctx context.Context, repoUrls []string, apiClient *apiclient.APIClient, projects *[]apiclient.CreateProjectDTO) ([]string, error) {
344344
if len(repoUrls) == 0 {
345345
return nil, fmt.Errorf("no repository URLs provided")
346346
}
@@ -358,15 +358,15 @@ func processCmdArguments(repoUrls []string, apiClient *apiclient.APIClient, proj
358358
existingProjectConfigNames := []string{}
359359

360360
for i, repoUrl := range repoUrls {
361-
branch := ""
361+
var branch *string
362362
if len(*projectConfigurationFlags.Branches) > i {
363-
branch = (*projectConfigurationFlags.Branches)[i]
363+
branch = &(*projectConfigurationFlags.Branches)[i]
364364
}
365365

366366
validatedUrl, err := util.GetValidatedUrl(repoUrl)
367367
if err == nil {
368368
// The argument is a Git URL
369-
existingProjectConfigName, err := processGitURL(ctx, validatedUrl, apiClient, projects, &branch)
369+
existingProjectConfigName, err := processGitURL(ctx, validatedUrl, apiClient, projects, branch)
370370
if err != nil {
371371
return nil, err
372372
}
@@ -407,11 +407,7 @@ func processGitURL(ctx context.Context, repoUrl string, apiClient *apiclient.API
407407
if !blankFlag {
408408
projectConfig, res, err := apiClient.ProjectConfigAPI.GetDefaultProjectConfig(ctx, encodedURLParam).Execute()
409409
if err == nil {
410-
b := ""
411-
if branch != nil {
412-
b = *branch
413-
}
414-
return workspace_util.AddProjectFromConfig(projectConfig, apiClient, projects, b)
410+
return workspace_util.AddProjectFromConfig(projectConfig, apiClient, projects, branch)
415411
}
416412

417413
if res.StatusCode != http.StatusNotFound {

pkg/cmd/workspace/util/add_from_config.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111
"github.com/daytonaio/daytona/pkg/common"
1212
)
1313

14-
func AddProjectFromConfig(projectConfig *apiclient.ProjectConfig, apiClient *apiclient.APIClient, projects *[]apiclient.CreateProjectDTO, branchFlag string) (*string, error) {
15-
chosenBranchName := branchFlag
14+
func AddProjectFromConfig(projectConfig *apiclient.ProjectConfig, apiClient *apiclient.APIClient, projects *[]apiclient.CreateProjectDTO, branchFlag *string) (*string, error) {
15+
chosenBranchName := ""
16+
if branchFlag != nil {
17+
chosenBranchName = *branchFlag
18+
}
1619

1720
if chosenBranchName == "" {
1821
chosenBranch, err := GetBranchFromProjectConfig(projectConfig, apiClient, 0)

0 commit comments

Comments
 (0)