Class: Ace::Git::Worktree::Molecules::TaskPusher
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Molecules::TaskPusher
- Defined in:
- lib/ace/git/worktree/molecules/task_pusher.rb
Overview
Task pusher molecule
Pushes task changes to remote repository after commits. Used by TaskWorktreeOrchestrator to ensure task status updates are visible in PRs.
Constant Summary collapse
- DEFAULT_TIMEOUT =
Default timeout for git push commands
60
Instance Method Summary collapse
-
#current_branch ⇒ String?
Get current branch name.
-
#get_upstream(branch = nil) ⇒ Hash?
Get the upstream remote/branch for current branch.
-
#has_upstream?(branch = nil) ⇒ Boolean
Check if branch has upstream tracking.
-
#initialize(timeout: DEFAULT_TIMEOUT) ⇒ TaskPusher
constructor
Initialize a new TaskPusher.
-
#push(remote: "origin", branch: nil, set_upstream: true) ⇒ Hash
Push current branch to remote.
-
#remote_exists?(remote) ⇒ Boolean
Check if remote exists.
-
#set_upstream(branch: nil, remote: "origin") ⇒ Hash
Set upstream tracking for a branch.
Constructor Details
#initialize(timeout: DEFAULT_TIMEOUT) ⇒ TaskPusher
Initialize a new TaskPusher
28 29 30 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 28 def initialize(timeout: DEFAULT_TIMEOUT) @timeout = timeout end |
Instance Method Details
#current_branch ⇒ String?
Get current branch name
81 82 83 84 85 86 87 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 81 def current_branch result = Atoms::GitCommand.execute("branch", "--show-current", timeout: 5) return nil unless result[:success] branch = result[:output]&.strip branch.empty? ? nil : branch end |
#get_upstream(branch = nil) ⇒ Hash?
Get the upstream remote/branch for current branch
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 144 def get_upstream(branch = nil) branch ||= current_branch return nil unless branch result = Atoms::GitCommand.execute( "rev-parse", "--abbrev-ref", "#{branch}@{upstream}", timeout: 5 ) return nil unless result[:success] upstream = result[:output]&.strip return nil if upstream.nil? || upstream.empty? # Parse "origin/branch-name" format parts = upstream.split("/", 2) return nil if parts.length < 2 {remote: parts[0], branch: parts[1]} end |
#has_upstream?(branch = nil) ⇒ Boolean
Check if branch has upstream tracking
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 96 def has_upstream?(branch = nil) branch ||= current_branch return false unless branch result = Atoms::GitCommand.execute( "rev-parse", "--abbrev-ref", "#{branch}@{upstream}", timeout: 5 ) result[:success] end |
#push(remote: "origin", branch: nil, set_upstream: true) ⇒ Hash
Push current branch to remote
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 43 def push(remote: "origin", branch: nil, set_upstream: true) branch ||= current_branch return failure_result("Could not determine current branch") unless branch args = ["push"] args << "-u" if set_upstream args << remote args << branch result = Atoms::GitCommand.execute(*args, timeout: @timeout) { success: result[:success], output: result[:output], error: result[:error], remote: remote, branch: branch } end |
#remote_exists?(remote) ⇒ Boolean
Check if remote exists
70 71 72 73 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 70 def remote_exists?(remote) result = Atoms::GitCommand.execute("remote", "get-url", remote, timeout: 5) result[:success] end |
#set_upstream(branch: nil, remote: "origin") ⇒ Hash
Set upstream tracking for a branch
Uses ‘git branch –set-upstream-to` to configure tracking without pushing. Useful when the remote branch already exists or push is not desired.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ace/git/worktree/molecules/task_pusher.rb', line 119 def set_upstream(branch: nil, remote: "origin") branch ||= current_branch return failure_result("Could not determine current branch") unless branch result = Atoms::GitCommand.execute( "branch", "--set-upstream-to=#{remote}/#{branch}", branch, timeout: @timeout ) { success: result[:success], output: result[:output], error: result[:error], remote: remote, branch: branch } end |