Class: Ace::Git::Worktree::Atoms::GitCommand
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Atoms::GitCommand
- Defined in:
- lib/ace/git/worktree/atoms/git_command.rb
Overview
Git command execution atom
Provides a thin wrapper around ace-git’s CommandExecutor for safe git command execution with proper error handling. This adapter maintains backward compatibility with the original API while delegating to the consolidated ace-git package.
Constant Summary collapse
- FALLBACK_TIMEOUT =
Fallback timeout for git commands (30 seconds) Used only when config is unavailable
30
Class Method Summary collapse
-
.current_branch ⇒ String?
Get current git branch name or commit SHA if in detached HEAD state.
-
.default_timeout ⇒ Integer
Get default timeout from config or fallback.
-
.execute(*args, timeout: nil) ⇒ Hash
Execute a git command safely using ace-git’s CommandExecutor.
-
.git_repository? ⇒ Boolean
Check if git repository exists.
-
.git_root ⇒ String?
Get git repository root directory.
-
.ref_exists?(ref) ⇒ Boolean
Check if a git ref (branch, tag, commit SHA) exists.
-
.worktree(*args, timeout: nil) ⇒ Hash
Execute a git worktree command.
Class Method Details
.current_branch ⇒ String?
Get current git branch name or commit SHA if in detached HEAD state
93 94 95 96 97 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 93 def current_branch # ace-git's current_branch now handles detached HEAD state # and returns SHA directly when detached Ace::Git::Atoms::CommandExecutor.current_branch end |
.default_timeout ⇒ Integer
Get default timeout from config or fallback
30 31 32 33 34 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 30 def default_timeout Ace::Git::Worktree.default_timeout rescue FALLBACK_TIMEOUT end |
.execute(*args, timeout: nil) ⇒ Hash
Execute a git command safely using ace-git’s CommandExecutor
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 45 def execute(*args, timeout: nil) timeout ||= default_timeout # Ensure all arguments are strings string_args = args.map(&:to_s) # Delegate to ace-git's CommandExecutor # Note: CommandExecutor expects "git" as first argument result = Ace::Git::Atoms::CommandExecutor.execute("git", *string_args, timeout:) # Normalize ace-git result keys for legacy compatibility { success: result[:success], output: result[:output].to_s, error: result[:error].to_s, exit_code: result[:exit_code] || 0 } rescue => e # Handle unexpected exceptions from ace-git to maintain defensive behavior { success: false, output: "", error: "Unexpected error: #{e.}", exit_code: 1 } end |
.git_repository? ⇒ Boolean
Check if git repository exists
86 87 88 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 86 def git_repository? Ace::Git::Atoms::CommandExecutor.in_git_repo? end |
.git_root ⇒ String?
Get git repository root directory
Delegates to ace-git’s CommandExecutor for repository root detection
113 114 115 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 113 def git_root Ace::Git::Atoms::CommandExecutor.repo_root end |
.ref_exists?(ref) ⇒ Boolean
Check if a git ref (branch, tag, commit SHA) exists
103 104 105 106 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 103 def ref_exists?(ref) result = execute("rev-parse", "--verify", "--quiet", ref, timeout: 5) result[:success] end |
.worktree(*args, timeout: nil) ⇒ Hash
Execute a git worktree command
79 80 81 |
# File 'lib/ace/git/worktree/atoms/git_command.rb', line 79 def worktree(*args, timeout: nil) execute("worktree", *args, timeout: timeout) end |