From 381bf7384ef9ebe6ddcf5be3b0a5f9a70003cd89 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 4 Oct 2024 11:44:30 +0000 Subject: [PATCH] fix when base is . --- integration/integration_test.go | 8 +++++--- options/defaults.go | 2 +- options/defaults_test.go | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index b7332c0..7fd732d 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -844,15 +844,17 @@ func TestContainerEnv(t *testing.T) { require.NoError(t, err) output := execContainer(t, ctr, "cat /env") - require.Contains(t, strings.TrimSpace(output), - `DEVCONTAINER=true + want := `DEVCONTAINER=true DEVCONTAINER_CONFIG=/workspaces/empty/.devcontainer/devcontainer.json ENVBUILDER=true FROM_CONTAINER_ENV=bar FROM_DOCKERFILE=foo FROM_REMOTE_ENV=baz PATH=/usr/local/bin:/bin:/go/bin:/opt -REMOTE_BAR=bar`) +REMOTE_BAR=bar` + if diff := cmp.Diff(want, strings.TrimSpace(output)); diff != "" { + require.Failf(t, "env mismatch", "diff (-want +got):\n%s", diff) + } } func TestUnsetOptionsEnv(t *testing.T) { diff --git a/options/defaults.go b/options/defaults.go index 0278aab..761e1de 100644 --- a/options/defaults.go +++ b/options/defaults.go @@ -30,7 +30,7 @@ func DefaultWorkspaceFolder(repoURL string) string { // Giturls parsing never actually fails since ParseLocal never // errors and places the entire URL in the Path field. This check // ensures it's at least a Unix path containing forwardslash. - if repo == repoURL || repo == "" { + if repo == repoURL || repo == "." || repo == "" { return EmptyWorkspaceDir } repo = strings.TrimSuffix(repo, ".git") diff --git a/options/defaults_test.go b/options/defaults_test.go index ec45e29..643bd1f 100644 --- a/options/defaults_test.go +++ b/options/defaults_test.go @@ -114,6 +114,10 @@ func TestDefaultWorkspaceFolder(t *testing.T) { name: "Unix root", invalidURL: "/", }, + { + name: "Git URL with no path", + invalidURL: "http://127.0.0.1:41073", + }, } for _, tt := range invalidTests { t.Run(tt.name, func(t *testing.T) {