Class: Ace::Git::Worktree::Molecules::TaskCommitter
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Molecules::TaskCommitter
- Defined in:
- lib/ace/git/worktree/molecules/task_committer.rb
Overview
Task committer molecule
Commits task file changes using ace-git-commit or direct git commands. Provides automatic commit message generation and handles commit operations.
Constant Summary collapse
- FALLBACK_TIMEOUT =
Fallback timeout for git commands Used only when config is unavailable
30
Instance Method Summary collapse
-
#ace_git_commit_available? ⇒ Boolean
Check if ace-git-commit is available.
-
#commit_all_changes(status, task_id = nil) ⇒ Boolean
Commit all changes with automatic message.
-
#commit_all_with_message(message) ⇒ Boolean
Commit all changes with specific message.
-
#commit_task_changes(files, status, task_id = nil) ⇒ Boolean
Commit task changes with automatic message generation.
-
#commit_with_message(files, message) ⇒ Boolean
Commit files with a specific message.
-
#get_file_status(files) ⇒ Hash
Get status of files.
-
#has_uncommitted_changes?(files = nil) ⇒ Boolean
Check if there are uncommitted changes.
-
#initialize(timeout: nil, use_ace_git_commit: true) ⇒ TaskCommitter
constructor
Initialize a new TaskCommitter.
Constructor Details
#initialize(timeout: nil, use_ace_git_commit: true) ⇒ TaskCommitter
Initialize a new TaskCommitter
27 28 29 30 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 27 def initialize(timeout: nil, use_ace_git_commit: true) @timeout = timeout || config_timeout @use_ace_git_commit = use_ace_git_commit end |
Instance Method Details
#ace_git_commit_available? ⇒ Boolean
Check if ace-git-commit is available
186 187 188 189 190 191 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 186 def ace_git_commit_available? return @ace_git_commit_available if defined?(@ace_git_commit_available) result = execute_command("ace-git-commit", "--version", timeout: 5) @ace_git_commit_available = result[:success] end |
#commit_all_changes(status, task_id = nil) ⇒ Boolean
Commit all changes with automatic message
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 97 def commit_all_changes(status, task_id = nil) # Only attempt commit if there are actually changes to commit unless has_uncommitted_changes? puts "No changes to commit" if ENV["DEBUG"] return true end = (status, task_id) () end |
#commit_all_with_message(message) ⇒ Boolean
Commit all changes with specific message
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 115 def () return false if .nil? || .empty? # Try ace-git-commit first if enabled if @use_ace_git_commit && ace_git_commit_available? return commit_all_with_ace_git_commit() end # Fallback to direct git commands commit_all_with_git() end |
#commit_task_changes(files, status, task_id = nil) ⇒ Boolean
Commit task changes with automatic message generation
54 55 56 57 58 59 60 61 62 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 54 def commit_task_changes(files, status, task_id = nil) return false if files.nil? || files.empty? return false if status.nil? || status.empty? # Generate commit message = (status, task_id) (files, ) end |
#commit_with_message(files, message) ⇒ Boolean
Commit files with a specific message
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 72 def (files, ) return false if files.nil? || files.empty? return false if .nil? || .empty? # Filter to only existing files existing_files = Array(files).select { |file| File.exist?(file) } return false if existing_files.empty? # Try ace-git-commit first if enabled if @use_ace_git_commit && ace_git_commit_available? return commit_with_ace_git_commit(existing_files, ) end # Fallback to direct git commands commit_with_git(existing_files, ) end |
#get_file_status(files) ⇒ Hash
Get status of files
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 159 def get_file_status(files) status = {} Array(files).each do |file| next unless File.exist?(file) result = execute_git_command("status", "--porcelain", file) if result[:success] line = result[:output].strip if line.empty? status[file] = "unmodified" else # Parse git status output format status_code = line[0, 2] status[file] = parse_status_code(status_code) end else status[file] = "error" end end status end |
#has_uncommitted_changes?(files = nil) ⇒ Boolean
Check if there are uncommitted changes
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ace/git/worktree/molecules/task_committer.rb', line 135 def has_uncommitted_changes?(files = nil) if files.nil? || files.empty? # Check all changes result = execute_git_command("status", "--porcelain") result[:success] && !result[:output].strip.empty? else # Check specific files files.any? do |file| next false unless File.exist?(file) result = execute_git_command("diff", "--quiet", file) !result[:success] end end end |