Module: Ace::Git::Worktree::Configuration

Defined in:
lib/ace/git/worktree/configuration.rb

Overview

Configuration module

Provides constants and utility methods for the ace-git-worktree gem. Configuration values are loaded from .ace/git/worktree.yml via ace-core cascade. Default values are defined in WorktreeConfig::DEFAULT_CONFIG.

Constant Summary collapse

GEM_NAME =

Gem name and identifier

"ace-git-worktree"
MISE_CONFIG_FILE =

File and directory names

"mise.toml"
CONFIG_FILE =
"worktree.yml"
CONFIG_NAMESPACE =

Configuration paths

["git", "worktree"].freeze
TEMPLATE_VARIABLES =

Template variable patterns

%w[id task_id slug].freeze
FORBIDDEN_BRANCH_CHARS =

Git branch name restrictions

/[~\^:*?\[\]]/
SEPARATOR_CHARS =
/[ ._\/\\]+/
TASK_STATUSES =

Task status values

%w[pending in-progress done blocked].freeze
TASK_PRIORITIES =

Task priority values

%w[high medium low].freeze
OUTPUT_FORMATS =

Output formats

%w[table json simple].freeze
CLI_COMMANDS =

CLI command names and aliases

{
  "create" => "Create a new worktree",
  "list" => "List all worktrees",
  "switch" => "Switch to a worktree",
  "remove" => "Remove a worktree",
  "prune" => "Clean up deleted worktrees",
  "config" => "Show/manage configuration"
}.freeze
CLI_ALIASES =
{
  "ls" => "list",
  "rm" => "remove",
  "cd" => "switch"
}.freeze
HELP_TEMPLATES =

Help text templates

{
  usage: "ace-git-worktree <command> [OPTIONS]",
  examples: "See 'ace-git-worktree <command> --help' for examples",
  config_help: "See 'ace-git-worktree config --files' for configuration locations"
}.freeze
ERROR_MESSAGES =

Error messages

{
  not_git_repo: "Not in a git repository",
  task_not_found: "Task not found",
  worktree_not_found: "Worktree not found",
  config_invalid: "Invalid configuration",
  command_failed: "Command failed",
  unexpected_error: "Unexpected error"
}.freeze
SUCCESS_MESSAGES =

Success messages

{
  worktree_created: "Worktree created successfully",
  worktree_removed: "Worktree removed successfully",
  config_valid: "Configuration is valid",
  cleanup_completed: "Cleanup completed successfully"
}.freeze
WARNING_MESSAGES =

Warning messages

{
  mise_trust_failed: "Failed to trust mise configuration",
  task_commit_failed: "Failed to commit task changes",
  metadata_add_failed: "Failed to add worktree metadata",
  uncommitted_changes: "Worktree has uncommitted changes"
}.freeze

Class Method Summary collapse

Class Method Details

.available_commandsArray<String>

Get all available commands

Returns:

  • (Array<String>)

    Array of command names



161
162
163
# File 'lib/ace/git/worktree/configuration.rb', line 161

def self.available_commands
  (CLI_COMMANDS.keys + CLI_ALIASES.keys).sort
end

.command_exists?(command_name) ⇒ Boolean

Check if command exists

Parameters:

  • command_name (String)

    Command name

Returns:

  • (Boolean)

    true if command exists



146
147
148
# File 'lib/ace/git/worktree/configuration.rb', line 146

def self.command_exists?(command_name)
  CLI_COMMANDS.key?(command_name) || CLI_ALIASES.key?(command_name)
end

.get_command_description(command_name) ⇒ String

Get command description

Parameters:

  • command_name (String)

    Command name

Returns:

  • (String)

    Command description or nil if not found



138
139
140
# File 'lib/ace/git/worktree/configuration.rb', line 138

def self.get_command_description(command_name)
  CLI_COMMANDS[command_name] || CLI_ALIASES[command_name]
end

.resolve_command_alias(command_name) ⇒ String

Resolve command alias

Parameters:

  • command_name (String)

    Command name or alias

Returns:

  • (String)

    Resolved command name



154
155
156
# File 'lib/ace/git/worktree/configuration.rb', line 154

def self.resolve_command_alias(command_name)
  CLI_ALIASES[command_name] || command_name
end

.validate_configuration(config) ⇒ Array<String>

Validate configuration hash

Parameters:

  • config (Hash)

    Configuration to validate

Returns:

  • (Array<String>)

    Array of error messages (empty if valid)



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ace/git/worktree/configuration.rb', line 102

def self.validate_configuration(config)
  errors = []

  # Validate root_path
  unless config["root_path"].is_a?(String) && !config["root_path"].empty?
    errors << "root_path must be a non-empty string"
  end

  # Validate task section
  task_config = config["task"] || {}

  unless task_config["directory_format"].is_a?(String) && !task_config["directory_format"].empty?
    errors << "task.directory_format must be a non-empty string"
  end

  unless task_config["branch_format"].is_a?(String) && !task_config["branch_format"].empty?
    errors << "task.branch_format must be a non-empty string"
  end

  # Validate template variables
  [task_config["directory_format"], task_config["branch_format"], task_config["commit_message_format"]].each do |template|
    next unless template.is_a?(String)

    missing = validate_template_variables(template)
    if missing.any?
      errors << "#{template} should include variables: #{missing.join(", ")}"
    end
  end

  errors
end

.validate_template_variables(template) ⇒ Array<String>

Validate template variables

Parameters:

  • template (String)

    Template string to validate

Returns:

  • (Array<String>)

    Array of missing variables (empty if valid)



91
92
93
94
95
96
# File 'lib/ace/git/worktree/configuration.rb', line 91

def self.validate_template_variables(template)
  return [] unless template.is_a?(String)

  used_variables = template.scan(/\{([^}]+)\}/).flatten
  TEMPLATE_VARIABLES - used_variables
end