Class: Ace::Git::Worktree::Molecules::TaskPusher

Inherits:
Object
  • Object
show all
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.

Examples:

Push to default remote

pusher = TaskPusher.new
result = pusher.push

Push to specific remote and branch

result = pusher.push(remote: "upstream", branch: "feature-branch")

Constant Summary collapse

DEFAULT_TIMEOUT =

Default timeout for git push commands

60

Instance Method Summary collapse

Constructor Details

#initialize(timeout: DEFAULT_TIMEOUT) ⇒ TaskPusher

Initialize a new TaskPusher

Parameters:

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    Command timeout in seconds



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_branchString?

Get current branch name

Examples:

pusher.current_branch # => "feature-branch"

Returns:

  • (String, nil)

    Current branch name or nil if detached



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

Examples:

pusher.get_upstream # => { remote: "origin", branch: "main" }

Parameters:

  • branch (String, nil) (defaults to: nil)

    Branch to check (default: current)

Returns:

  • (Hash, nil)

    Hash with :remote and :branch keys, or nil



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

Examples:

pusher.has_upstream? # => true

Parameters:

  • branch (String, nil) (defaults to: nil)

    Branch to check (default: current)

Returns:

  • (Boolean)

    true if branch has upstream



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

Examples:

pusher = TaskPusher.new
result = pusher.push(remote: "origin")
result[:success] # => true

Parameters:

  • remote (String) (defaults to: "origin")

    Remote name (default: “origin”)

  • branch (String, nil) (defaults to: nil)

    Branch name (default: current branch)

  • set_upstream (Boolean) (defaults to: true)

    Set upstream tracking (default: true)

Returns:

  • (Hash)

    Result with :success, :output, :error



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

Examples:

pusher.remote_exists?("origin") # => true

Parameters:

  • remote (String)

    Remote name to check

Returns:

  • (Boolean)

    true 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.

Examples:

pusher.set_upstream(branch: "feature", remote: "origin")
# => { success: true, branch: "feature", remote: "origin", ... }

Parameters:

  • branch (String, nil) (defaults to: nil)

    Branch to configure (default: current)

  • remote (String) (defaults to: "origin")

    Remote name (default: “origin”)

Returns:

  • (Hash)

    Result with :success, :output, :error, :remote, :branch



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