format

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package format handles worktree folder name generation and path sanitization.

Worktree folders are named using a configurable format string with placeholders that are substituted at creation time.

Format Placeholders

Available placeholders for worktree_format config:

  • {repo}: Repository name extracted from git remote origin URL
  • {branch}: Branch name as provided to the command
  • {folder}: Actual folder name of the git repo on disk

Default format is "{repo}-{branch}", creating folders like "my-repo-feature-x".

Path Sanitization

Branch and repo names are sanitized to create valid filesystem paths. Characters replaced with "-": / \ : * ? " < > |

This ensures branches like "feature/my-branch" become "feature-my-branch" in the folder name.

Validation

Use ValidateFormat to check format strings before use. It ensures:

  • All placeholders are recognized
  • At least one placeholder is present (pure static names aren't useful)

Index

Constants

View Source
const DefaultWorktreeFormat = "{repo}-{branch}"

DefaultWorktreeFormat is the default format for worktree folder names

Variables

View Source
var ValidPlaceholders = []string{"{repo}", "{branch}", "{folder}"}

ValidPlaceholders lists all supported placeholders

Functions

func FormatWorktreeName

func FormatWorktreeName(format string, params FormatParams) string

FormatWorktreeName applies the format template to generate a worktree folder name

func SanitizeForPath

func SanitizeForPath(name string) string

SanitizeForPath replaces characters that are problematic in file paths Replaces: / \ : * ? " < > | with -

func ValidateFormat

func ValidateFormat(format string) error

ValidateFormat checks if a format string is valid Returns error if format contains unknown placeholders

Types

type FormatParams

type FormatParams struct {
	GitOrigin  string // repo name from git remote get-url origin
	BranchName string // branch name as provided
	FolderName string // actual folder name of git repo on disk
}

FormatParams contains the values for placeholder substitution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL