@@ -42,7 +42,8 @@ class RepositoryProjectPathConfigSerializer(CamelSnakeModelSerializer):
4242 source_root = gen_path_regex_field ()
4343 default_branch = serializers .RegexField (
4444 r"^(^(?![\/]))([\w\.\/-]+)(?<![\/])$" ,
45- required = True ,
45+ required = False , # Validated in validate_default_branch based on integration type
46+ allow_blank = True , # Perforce allows empty streams
4647 error_messages = {"invalid" : _ (BRANCH_NAME_ERROR_MESSAGE )},
4748 )
4849 instance : RepositoryProjectPathConfig | None
@@ -98,6 +99,24 @@ def validate_project_id(self, project_id):
9899 raise serializers .ValidationError ("Project does not exist" )
99100 return project_id
100101
102+ def validate_default_branch (self , default_branch ):
103+ # Get the integration to check if it's Perforce
104+ integration = integration_service .get_integration (
105+ integration_id = self .org_integration .integration_id
106+ )
107+
108+ # For Perforce, allow empty branch (streams are part of depot path)
109+ if integration and integration .provider == "perforce" :
110+ # Allow empty string for Perforce
111+ if not default_branch :
112+ return default_branch
113+ else :
114+ # For other integrations, branch is required
115+ if not default_branch :
116+ raise serializers .ValidationError ("This field is required." )
117+
118+ return default_branch
119+
101120 def create (self , validated_data ):
102121 return RepositoryProjectPathConfig .objects .create (
103122 organization_integration_id = self .org_integration .id ,
0 commit comments