Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ describe('SourceControlPreferencesService', () => {
expect(validationResult).toBeTruthy();
});

describe('branchName validation', () => {
it.each(['main', 'develop', 'feature/my-branch', 'release-1.0', 'v2.3.4'])(
'should accept valid branch name: %s',
async (branchName) => {
await expect(
service.validateSourceControlPreferences({ branchName }),
).resolves.not.toThrow();
},
);

it.each(['--option-like-value', '-flag', '--receive-pack=cmd', '--upload-pack=cmd'])(
'should reject branch name that does not start with an alphanumeric character: %s',
async (branchName) => {
await expect(service.validateSourceControlPreferences({ branchName })).rejects.toThrow(
'Invalid source control preferences',
);
},
);
});

describe('line ending normalization', () => {
let tempDir: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsBoolean, IsHexColor, IsOptional, IsString, IsIn } from 'class-validator';
import { IsBoolean, IsHexColor, IsOptional, IsString, IsIn, Matches } from 'class-validator';

import { KeyPairType } from './key-pair-type';

Expand All @@ -14,6 +14,9 @@ export class SourceControlPreferences {
repositoryUrl: string;

@IsString()
@Matches(/^[a-zA-Z0-9]/, {

@cubic-dev-ai cubic-dev-ai Bot Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new @Matches rule does not validate Git branch format correctly: it rejects valid names (e.g. _feature) and still allows invalid names (e.g. a..b). Use full ref-format validation instead of a first-character check.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli/src/modules/source-control.ee/types/source-control-preferences.ts, line 17:

<comment>The new `@Matches` rule does not validate Git branch format correctly: it rejects valid names (e.g. `_feature`) and still allows invalid names (e.g. `a..b`). Use full ref-format validation instead of a first-character check.</comment>

<file context>
@@ -14,6 +14,9 @@ export class SourceControlPreferences {
 	repositoryUrl: string;
 
 	@IsString()
+	@Matches(/^[a-zA-Z0-9]/, {
+		message: 'branchName must start with an alphanumeric character',
+	})
</file context>
Fix with Cubic

message: 'branchName must start with an alphanumeric character',
})
branchName = 'main';

@IsBoolean()
Expand Down
Loading