Documentation
¶
Overview ¶
Package branch provides branch name sanitization functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBranchNameContainsAtBrace = &Error{message: "branch name cannot contain the sequence @{"}
ErrBranchNameContainsAtBrace is returned when the branch name contains the sequence @{.
var ErrBranchNameContainsBackslash = &Error{message: "branch name cannot contain backslash"}
ErrBranchNameContainsBackslash is returned when the branch name contains a backslash.
var ErrBranchNameEmpty = &Error{message: "branch name cannot be empty"}
ErrBranchNameEmpty is returned when the branch name is empty.
var ErrBranchNameEmptyAfterSanitization = &Error{message: "branch name becomes empty after sanitization"}
ErrBranchNameEmptyAfterSanitization is returned when the branch name becomes empty after sanitization.
var ErrBranchNameSingleAt = &Error{message: "branch name cannot be the single character @"}
ErrBranchNameSingleAt is returned when the branch name is just a single @ character.
Functions ¶
func SanitizeBranchName ¶
SanitizeBranchName sanitizes a branch name according to Git's branch naming rules. Git imposes the following rules on how references are named:
- They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.
- They cannot have two consecutive dots .. anywhere.
- They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.
- They cannot have question-mark ?, asterisk *, or open bracket [ anywhere.
- They cannot begin or end with a slash / or contain multiple consecutive slashes.
- They cannot end with a dot .
- They cannot contain a sequence @{.
- They cannot be the single character @.
- They cannot contain a \.
- Additional rule for branch names: They cannot start with a dash -.
func SanitizeBranchNameForFilename ¶ added in v0.26.0
SanitizeBranchNameForFilename sanitizes a branch name for use in filenames. This replaces filesystem-unsafe characters (like /) with safe alternatives.