Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to folders.FindDirWithLeaf #1963

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions internal/bundle/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/filer"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/cli/libs/git"
"github.com/databricks/cli/libs/template"
"github.com/databricks/cli/libs/vfs"
"github.com/databricks/databricks-sdk-go"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -144,15 +144,14 @@ func getBundleRemoteRootPath(w *databricks.WorkspaceClient, t *testing.T, unique
}

func blackBoxRun(t *testing.T, root string, args ...string) (stdout string, stderr string) {
cwd := vfs.MustNew(".")
gitRoot, err := vfs.FindLeafInTree(cwd, ".git")
gitRoot, err := git.FindLeafInTree(".", ".git")
require.NoError(t, err)

t.Setenv("BUNDLE_ROOT", root)

// Create the command
cmd := exec.Command("go", append([]string{"run", "main.go"}, args...)...)
cmd.Dir = gitRoot.Native()
cmd.Dir = gitRoot

// Create buffers to capture output
var outBuffer, errBuffer bytes.Buffer
Expand Down
9 changes: 6 additions & 3 deletions libs/git/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func ensureWorkspacePrefix(p string) string {
func fetchRepositoryInfoDotGit(ctx context.Context, path string) (RepositoryInfo, error) {
result := RepositoryInfo{}

rootDir, err := findLeafInTree(path, GitDirectoryName)
rootDir, err := FindLeafInTree(path, GitDirectoryName)
if rootDir == "" {
return result, err
}
Expand Down Expand Up @@ -135,8 +135,11 @@ func fetchRepositoryInfoDotGit(ctx context.Context, path string) (RepositoryInfo
return result, nil
}

func findLeafInTree(p string, leafName string) (string, error) {
var err error
func FindLeafInTree(p string, leafName string) (string, error) {
p, err := filepath.Abs(p)
if err != nil {
return "", err
}
for i := 0; i < 10000; i++ {
_, err = os.Stat(filepath.Join(p, leafName))

Expand Down
16 changes: 8 additions & 8 deletions libs/vfs/leaf_test.go → libs/git/info_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vfs
package git

import (
"os"
Expand All @@ -17,22 +17,22 @@ func TestFindLeafInTree(t *testing.T) {

// Find from working directory should work.
{
out, err := FindLeafInTree(MustNew(wd), ".git")
out, err := FindLeafInTree(wd, ".git")
assert.NoError(t, err)
assert.Equal(t, root, out.Native())
assert.Equal(t, root, out)
}

// Find from project root itself should work.
{
out, err := FindLeafInTree(MustNew(root), ".git")
out, err := FindLeafInTree(root, ".git")
assert.NoError(t, err)
assert.Equal(t, root, out.Native())
assert.Equal(t, root, out)
}

// Find for something that doesn't exist should work.
{
out, err := FindLeafInTree(MustNew(root), "this-leaf-doesnt-exist-anywhere")
assert.ErrorIs(t, err, os.ErrNotExist)
assert.Equal(t, nil, out)
out, err := FindLeafInTree(root, "this-leaf-doesnt-exist-anywhere")
assert.NoError(t, err)
assert.Equal(t, "", out)
}
}
29 changes: 0 additions & 29 deletions libs/vfs/leaf.go

This file was deleted.

Loading