-
Notifications
You must be signed in to change notification settings - Fork 213
Read git metadata from the Repos API for Git CLI folders #6303
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
832c931
Read git metadata from the Repos API for Git CLI folders
denik 62bde6a
Cover the Git CLI folder metadata path with an acceptance test
denik 692f1c3
Export FetchRepositoryInfoAPI instead of wrapping it
denik aa1a52f
Simplify the fetch-repository-info debug command and its test
denik fb97325
Report the Git folder root without the /Workspace prefix in the fake
denik 306dfe3
Cover the failed Repos read with an acceptance test
denik 6d1993b
Narrow the testserver git_info tests to the response shape
denik b7651e4
acc: register the fault before exporting MSYS_NO_PATHCONV
denik 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed `bundle.git.branch`, `bundle.git.commit`, and `bundle.git.origin_url` being empty for bundles deployed from a workspace Git folder that has Git CLI access. The workspace API does not report git metadata for those folders, so it is now read from the Repos API instead. |
2 changes: 2 additions & 0 deletions
2
acceptance/bundle/debug/fetch-repository-info-repos-error/databricks.yml
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,2 @@ | ||
| bundle: | ||
| name: test-bundle |
2 changes: 2 additions & 0 deletions
2
acceptance/bundle/debug/fetch-repository-info-repos-error/out.test.toml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
acceptance/bundle/debug/fetch-repository-info-repos-error/output.txt
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,9 @@ | ||
|
|
||
| >>> [CLI] bundle debug fetch-repository-info --path /Workspace/Users/[USERNAME]/test-folder-[UNIQUE_NAME] | ||
| Warn: failed to load git info for repo [NUMID]: Fault injected by test. | ||
| { | ||
| "worktree_root": "/Workspace/Users/[USERNAME]/test-folder-[UNIQUE_NAME]", | ||
| "current_branch": "", | ||
| "latest_commit": "", | ||
| "origin_url": "" | ||
| } |
16 changes: 16 additions & 0 deletions
16
acceptance/bundle/debug/fetch-repository-info-repos-error/script
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,16 @@ | ||
| # A Git folder outside /Repos has Git CLI access, so the workspace API reports no | ||
| # git metadata for it and it is read from the Repos API instead. Make that read | ||
| # fail: the worktree root must still be reported, with the metadata left empty | ||
| # rather than failing the command. | ||
| # | ||
| # Registered before MSYS_NO_PATHCONV is exported, which on Windows would rewrite | ||
| # the path Git Bash passes for this helper's own script. | ||
| fault.py "GET /api/2.0/repos/*" 403 0 1 | ||
|
|
||
| # Keep Git Bash from rewriting the /Workspace path passed to --path. | ||
| export MSYS_NO_PATHCONV=1 | ||
|
|
||
| folder=/Workspace/Users/$CURRENT_USER_NAME/test-folder-$UNIQUE_NAME | ||
| $CLI repos create https://github.com/databricks/bundle-examples gitHub --path "$folder" > /dev/null | ||
|
|
||
| trace $CLI bundle debug fetch-repository-info --path "$folder" |
5 changes: 5 additions & 0 deletions
5
acceptance/bundle/debug/fetch-repository-info-repos-error/test.toml
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,5 @@ | ||
| # Local only: the failure is injected into the testserver. | ||
| Cloud = false | ||
|
|
||
| # This exercises git.FetchRepositoryInfo, which is independent of the deploy engine. | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] |
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,2 @@ | ||
| bundle: | ||
| name: test-bundle |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
|
|
||
| === the root of a Git folder under /Repos | ||
|
|
||
| >>> [CLI] bundle debug fetch-repository-info --path /Workspace/Repos/[USERNAME]/test-repo-[UNIQUE_NAME] | ||
| { | ||
| "worktree_root": "/Workspace/Repos/[USERNAME]/test-repo-[UNIQUE_NAME]", | ||
| "current_branch": "main", | ||
| "latest_commit": "[COMMIT_SHA]", | ||
| "origin_url": "https://github.com/databricks/bundle-examples" | ||
| } | ||
|
|
||
| === a subdirectory of it, which resolves to the same root | ||
|
|
||
| >>> [CLI] bundle debug fetch-repository-info --path /Workspace/Repos/[USERNAME]/test-repo-[UNIQUE_NAME]/subdir | ||
| { | ||
| "worktree_root": "/Workspace/Repos/[USERNAME]/test-repo-[UNIQUE_NAME]", | ||
| "current_branch": "main", | ||
| "latest_commit": "[COMMIT_SHA]", | ||
| "origin_url": "https://github.com/databricks/bundle-examples" | ||
| } | ||
|
|
||
| === the root of a Git folder outside /Repos | ||
|
|
||
| >>> [CLI] bundle debug fetch-repository-info --path /Workspace/Users/[USERNAME]/test-folder-[UNIQUE_NAME] | ||
| { | ||
| "worktree_root": "/Workspace/Users/[USERNAME]/test-folder-[UNIQUE_NAME]", | ||
| "current_branch": "main", | ||
| "latest_commit": "[COMMIT_SHA]", | ||
| "origin_url": "https://github.com/databricks/bundle-examples" | ||
| } | ||
|
|
||
| === a path in no Git folder at all | ||
|
|
||
| >>> [CLI] bundle debug fetch-repository-info --path /Workspace/Users/[USERNAME] | ||
| { | ||
| "worktree_root": "", | ||
| "current_branch": "", | ||
| "latest_commit": "", | ||
| "origin_url": "" | ||
| } |
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,33 @@ | ||
| # The fake workspace reports "main", which is this repo's default branch too. | ||
| url=https://github.com/databricks/bundle-examples | ||
|
|
||
| # A Git folder under /Repos and one outside it. Once a Git folder has Git CLI | ||
| # access the workspace API reports no git metadata for it, so both resolve | ||
| # through the Repos API; the resolved metadata must be identical either way. | ||
| repo=/Workspace/Repos/$CURRENT_USER_NAME/test-repo-$UNIQUE_NAME | ||
| folder=/Workspace/Users/$CURRENT_USER_NAME/test-folder-$UNIQUE_NAME | ||
|
|
||
| $CLI repos create $url gitHub --path "$repo" > /dev/null | ||
| $CLI repos create $url gitHub --path "$folder" > /dev/null | ||
|
|
||
| # A directory inside the Git folder, so the subdirectory case below resolves a | ||
| # path that exists rather than a missing one. | ||
| $CLI workspace mkdirs "$repo/subdir" | ||
|
|
||
| cleanup() { | ||
| $CLI repos delete "$repo" 2>>LOG.cleanup | ||
| $CLI repos delete "$folder" 2>>LOG.cleanup | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| title "the root of a Git folder under /Repos\n" | ||
| trace $CLI bundle debug fetch-repository-info --path "$repo" | ||
|
|
||
| title "a subdirectory of it, which resolves to the same root\n" | ||
| trace $CLI bundle debug fetch-repository-info --path "$repo/subdir" | ||
|
|
||
| title "the root of a Git folder outside /Repos\n" | ||
| trace $CLI bundle debug fetch-repository-info --path "$folder" | ||
|
|
||
| title "a path in no Git folder at all\n" | ||
| trace $CLI bundle debug fetch-repository-info --path "/Workspace/Users/$CURRENT_USER_NAME" |
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,13 @@ | ||
| Cloud = true | ||
|
|
||
| # This exercises git.FetchRepositoryInfo, which is independent of the deploy engine. | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
|
|
||
| # Keep Git Bash from rewriting the /Workspace paths passed to --path. | ||
| Env.MSYS_NO_PATHCONV = "1" | ||
|
|
||
| # The commit differs between the fake workspace and a real clone of the repo, so | ||
| # the golden matches both. | ||
| [[Repls]] | ||
| Old = '\b[0-9a-f]{40}\b' | ||
| New = '[COMMIT_SHA]' |
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
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
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
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,63 @@ | ||
| package debug | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/databricks/cli/cmd/root" | ||
| "github.com/databricks/cli/libs/cmdctx" | ||
| "github.com/databricks/cli/libs/git" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // repositoryInfoOutput mirrors git.RepositoryInfo, which has no JSON tags. | ||
| type repositoryInfoOutput struct { | ||
| WorktreeRoot string `json:"worktree_root"` | ||
| CurrentBranch string `json:"current_branch"` | ||
| LatestCommit string `json:"latest_commit"` | ||
| OriginURL string `json:"origin_url"` | ||
| } | ||
|
|
||
| // NewFetchRepositoryInfoCommand returns a command that reports what | ||
| // [git.FetchRepositoryInfoAPI] resolves for a path. It exists so that function | ||
| // can be exercised through the CLI on both a fake and a real workspace; nothing | ||
| // in the product calls it. | ||
| // | ||
| // It always reads the workspace API, which [git.FetchRepositoryInfo] only does on | ||
| // a Databricks Runtime. That cannot be detected off-cluster, and reading .git is | ||
| // covered by the TestFetchRepositoryInfoDotGit integration tests. | ||
| func NewFetchRepositoryInfoCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "fetch-repository-info", | ||
| Short: "Report the git metadata the workspace API resolves for a path", | ||
| Args: root.NoArgs, | ||
| Hidden: true, | ||
| } | ||
|
|
||
| var path string | ||
| cmd.Flags().StringVar(&path, "path", ".", "Path to resolve git metadata for") | ||
|
|
||
| cmd.PreRunE = root.MustWorkspaceClient | ||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
|
|
||
| info, err := git.FetchRepositoryInfoAPI(ctx, path, cmdctx.WorkspaceClient(ctx)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| buf, err := json.MarshalIndent(repositoryInfoOutput{ | ||
| WorktreeRoot: info.WorktreeRoot, | ||
| CurrentBranch: info.CurrentBranch, | ||
| LatestCommit: info.LatestCommit, | ||
| OriginURL: info.OriginURL, | ||
| }, "", " ") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = cmd.OutOrStdout().Write(append(buf, '\n')) | ||
| return err | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have it if nothing in product calls it? For acceptance tests? We seem to have
TestFetchRepositoryInfoAPI*unit tests which covers (somewhat?) the sameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for acc tests so we can have local + cloud test and deprecate corresponding integration/ tests