Repository navigation
Fix Git metadata detection for Workspace worktrees #7033
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
Merged
lennartkats-db
merged 6 commits into
main
from
lennart/fix-workspace-worktree-git-metadata
Oct 14, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
30d48ec
Fix Workspace Git metadata detection for linked worktrees
lennartkats-db b06381a
Merge remote-tracking branch 'origin/main' into lennart/fix-workspace…
lennartkats-db c769f09
Link changelog entry to PR 7033
lennartkats-db da89aa7
Remove changelog entry for Workspace worktree fix
lennartkats-db 38e3e5e
Fall back to local Git metadata in Workspace worktrees
lennartkats-db 7194af3
Keep local Git reader unchanged for Workspace fallback
lennartkats-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package git | ||
|
|
||
| import ( | ||
| "io/fs" | ||
| "net/http" | ||
| "net/url" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/internal/testutil" | ||
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/databricks/databricks-sdk-go/apierr" | ||
| "github.com/databricks/databricks-sdk-go/qa" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestFetchRepositoryInfoFromWorkspace(t *testing.T) { | ||
| dir := setupWorktree(t) | ||
| worktree := filepath.Join(dir, "my_worktree") | ||
| writeGitDir(t, dir, "gitdir: ../.git/worktrees/my_worktree") | ||
| writeGitCommonDir(t, dir, "../..") | ||
| want := RepositoryInfo{ | ||
| OriginURL: "https://example.test/repo.git", | ||
| LatestCommit: strings.Repeat("1", 40), | ||
| CurrentBranch: "projects/task", | ||
| WorktreeRoot: worktree, | ||
| } | ||
| gitDirectoryWant := want | ||
| gitDirectoryWant.WorktreeRoot = dir | ||
| noGitRoot := filepath.VolumeName(dir) + string(filepath.Separator) | ||
| testutil.WriteFile(t, filepath.Join(dir, ".git", "refs", "heads", want.CurrentBranch), want.LatestCommit) | ||
| testutil.WriteFile(t, filepath.Join(dir, ".git", "HEAD"), "ref: refs/heads/"+want.CurrentBranch) | ||
| testutil.WriteFile(t, filepath.Join(dir, ".git", "worktrees", "my_worktree", "HEAD"), "ref: refs/heads/"+want.CurrentBranch) | ||
| testutil.WriteFile(t, filepath.Join(dir, ".git", "config"), "[remote \"origin\"]\n\turl = "+want.OriginURL) | ||
| file := testutil.Touch(t, worktree, "subdir", "README.md") | ||
| malformed := t.TempDir() | ||
| testutil.WriteFile(t, filepath.Join(malformed, ".git"), "invalid gitfile") | ||
|
|
||
| for _, tc := range []struct { | ||
| name string | ||
| path string | ||
| body string | ||
| status int | ||
| want RepositoryInfo | ||
| wantErr error | ||
| }{ | ||
| {name: "worktree", path: worktree, want: want}, | ||
| {name: "subdirectory", path: filepath.Dir(file), want: want}, | ||
| { | ||
| name: "workspace metadata takes precedence", path: worktree, | ||
| body: `{"git_info":{"branch":"api-main","head_commit_id":"2222222222222222222222222222222222222222","path":"/Users/me/api","url":"https://example.test/api.git"}}`, | ||
| want: RepositoryInfo{ | ||
| OriginURL: "https://example.test/api.git", LatestCommit: strings.Repeat("2", 40), | ||
| CurrentBranch: "api-main", WorktreeRoot: "/Workspace/Users/me/api", | ||
| }, | ||
| }, | ||
| {name: "git directory", path: dir, want: gitDirectoryWant}, | ||
| {name: "no git metadata", path: noGitRoot, wantErr: fs.ErrNotExist}, | ||
| {name: "malformed gitfile", path: malformed, want: RepositoryInfo{WorktreeRoot: malformed}}, | ||
| { | ||
| name: "permission denied", path: worktree, status: http.StatusForbidden, | ||
| body: `{"error_code":"PERMISSION_DENIED","message":"denied"}`, wantErr: apierr.ErrPermissionDenied, | ||
| }, | ||
| { | ||
| name: "workspace path missing", path: worktree, status: http.StatusNotFound, | ||
| body: `{"error_code":"RESOURCE_DOES_NOT_EXIST","message":"missing"}`, wantErr: fs.ErrNotExist, | ||
| }, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| body := tc.body | ||
| if body == "" { | ||
| body = `{}` | ||
| } | ||
| cfg, server := qa.HTTPFixtures{{ | ||
| Method: "GET", | ||
| Resource: "/api/2.0/workspace/get-status?path=" + url.QueryEscape(tc.path) + "&return_git_info=true", | ||
| Response: body, | ||
| Status: tc.status, | ||
| }}.Config(t) | ||
| t.Cleanup(server.Close) | ||
| w := databricks.Must(databricks.NewWorkspaceClient((*databricks.Config)(cfg))) | ||
|
|
||
| got, err := fetchRepositoryInfoFromWorkspace(t.Context(), tc.path, w) | ||
| require.ErrorIs(t, err, tc.wantErr) | ||
| assert.Equal(t, tc.want, got) | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.