2023-07-30 12:44:33 +00:00
package mutator
import (
"context"
"github.com/databricks/cli/bundle"
2024-03-25 14:18:47 +00:00
"github.com/databricks/cli/libs/diag"
2023-07-30 12:44:33 +00:00
)
type validateGitDetails struct { }
func ValidateGitDetails ( ) * validateGitDetails {
return & validateGitDetails { }
}
func ( m * validateGitDetails ) Name ( ) string {
return "ValidateGitDetails"
}
2024-03-25 14:18:47 +00:00
func ( m * validateGitDetails ) Apply ( ctx context . Context , b * bundle . Bundle ) diag . Diagnostics {
2023-07-30 12:44:33 +00:00
if b . Config . Bundle . Git . Branch == "" || b . Config . Bundle . Git . ActualBranch == "" {
return nil
}
if b . Config . Bundle . Git . Branch != b . Config . Bundle . Git . ActualBranch && ! b . Config . Bundle . Force {
2024-03-25 14:18:47 +00:00
return diag . 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 )
2023-07-30 12:44:33 +00:00
}
return nil
}