Skip to content

Commit 84d535a

Browse files
committed
Move loadGitDetails mutator to Initialize phase
This will require API call and we want to keep Load phase fast.
1 parent 7b9726d commit 84d535a

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

bundle/config/mutator/mutator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func DefaultMutators() []bundle.Mutator {
2626
ComputeIdToClusterId(),
2727
InitializeVariables(),
2828
DefineDefaultTarget(),
29-
LoadGitDetails(),
3029
pythonmutator.PythonMutator(pythonmutator.PythonMutatorPhaseLoad),
3130

3231
// Note: This mutator must run before the target overrides are merged.

bundle/phases/initialize.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func Initialize() bundle.Mutator {
3939
mutator.MergePipelineClusters(),
4040
mutator.InitializeWorkspaceClient(),
4141
mutator.PopulateCurrentUser(),
42+
mutator.LoadGitDetails(),
4243

4344
mutator.DefineDefaultWorkspaceRoot(),
4445
mutator.ExpandWorkspaceRoot(),

bundle/tests/environment_git_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
package config_tests
22

33
import (
4+
"context"
45
"fmt"
56
"strings"
67
"testing"
78

9+
"github.com/databricks/cli/bundle"
10+
"github.com/databricks/cli/bundle/config/mutator"
811
"github.com/stretchr/testify/assert"
912
)
1013

1114
func TestGitAutoLoadWithEnvironment(t *testing.T) {
1215
b := load(t, "./environments_autoload_git")
16+
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
1317
assert.True(t, b.Config.Bundle.Git.Inferred)
1418
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
1519
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
1620
}
1721

1822
func TestGitManuallySetBranchWithEnvironment(t *testing.T) {
1923
b := loadTarget(t, "./environments_autoload_git", "production")
24+
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
2025
assert.False(t, b.Config.Bundle.Git.Inferred)
2126
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
2227
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")

bundle/tests/git_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import (
1414

1515
func TestGitAutoLoad(t *testing.T) {
1616
b := load(t, "./autoload_git")
17+
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
1718
assert.True(t, b.Config.Bundle.Git.Inferred)
1819
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
1920
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
2021
}
2122

2223
func TestGitManuallySetBranch(t *testing.T) {
2324
b := loadTarget(t, "./autoload_git", "production")
25+
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
2426
assert.False(t, b.Config.Bundle.Git.Inferred)
2527
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
2628
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
@@ -34,6 +36,7 @@ func TestGitBundleBranchValidation(t *testing.T) {
3436
})
3537

3638
b := load(t, "./git_branch_validation")
39+
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
3740
assert.False(t, b.Config.Bundle.Git.Inferred)
3841
assert.Equal(t, "feature-a", b.Config.Bundle.Git.Branch)
3942
assert.Equal(t, "feature-b", b.Config.Bundle.Git.ActualBranch)

0 commit comments

Comments
 (0)