github.com/databricks/cli@v0.203.0/bundle/config/mutator/validate_git_details.go (about)

     1  package mutator
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/databricks/cli/bundle"
     8  )
     9  
    10  type validateGitDetails struct{}
    11  
    12  func ValidateGitDetails() *validateGitDetails {
    13  	return &validateGitDetails{}
    14  }
    15  
    16  func (m *validateGitDetails) Name() string {
    17  	return "ValidateGitDetails"
    18  }
    19  
    20  func (m *validateGitDetails) Apply(ctx context.Context, b *bundle.Bundle) error {
    21  	if b.Config.Bundle.Git.Branch == "" || b.Config.Bundle.Git.ActualBranch == "" {
    22  		return nil
    23  	}
    24  
    25  	if b.Config.Bundle.Git.Branch != b.Config.Bundle.Git.ActualBranch && !b.Config.Bundle.Force {
    26  		return fmt.Errorf("not on the right Git branch:\n  expected according to configuration: %s\n  actual: %s\nuse --force to override", b.Config.Bundle.Git.Branch, b.Config.Bundle.Git.ActualBranch)
    27  	}
    28  	return nil
    29  }