class GitCommands::Computer

Attributes

out[R]

Public Class Methods

new(repo:, branches:, origin: Branch::ORIGIN, default: Branch::DEFAULT, repo_klass: Repository, branch_klass: Branch, out: STDOUT) click to toggle source
# File lib/git_commands/computer.rb, line 14
def initialize(repo:, branches:, origin: Branch::ORIGIN, default: Branch::DEFAULT, repo_klass: Repository, branch_klass: Branch, out: STDOUT)
  @out = out
  @repo = repo_klass.new(repo)
  @origin = origin
  @default = default
  Dir.chdir(@repo) do
    @branches = branch_klass.factory(branches)
    print_branches
  end
end

Public Instance Methods

aggregate(aggregator = Aggregator.new) click to toggle source
# File lib/git_commands/computer.rb, line 53
def aggregate(aggregator = Aggregator.new)
  temp = "temp/#{aggregator.timestamp}"
  aggregate_name = aggregator.call 
  confirm("Aggregate branches into #{aggregate_name}") do
    enter_repo do
      `git branch #{aggregate_name}`
      @branches.each do |branch|
        warning("Merging branch: #{branch}")
        `git checkout -b #{temp} origin/#{branch} --no-track`
        clean_and_exit([temp, aggregate_name]) unless rebase_with
        clean_and_exit([temp]) unless rebase_with(aggregate_name)
        `git checkout #{aggregate_name}`
        `git merge #{temp}`
        `git branch -D #{temp}`
      end      
    end
    success("#{aggregate_name} branch created")
  end
end
rebase() click to toggle source
# File lib/git_commands/computer.rb, line 37
def rebase
  confirm("Proceed rebasing these branches with: #{local_def}") do
    enter_repo do
      @branches.each do |branch|
        warning("Rebasing branch: #{branch}")
        `git checkout #{branch}`
        `git pull -r origin #{branch}`
        next unless rebase_with
        `git push --force-with-lease origin #{branch}`
        success("Rebased successfully!")
      end
      remove_locals
    end
  end
end
remove() click to toggle source
# File lib/git_commands/computer.rb, line 25
def remove
  enter_repo do
    confirm("Proceed removing these branches") do
      @branches.each do |branch|
        warning("Removing branch: #{branch}")
        `git branch -D #{branch}` if branch.exists?(false)
        `git push origin :#{branch}`
      end
    end
  end
end

Private Instance Methods

align() click to toggle source
# File lib/git_commands/computer.rb, line 81
        def align
  `git fetch #{@origin} #{@default}`
  `git fetch origin`
  `git checkout #{@default}`
  `git pull -r`
end
clean_and_exit(branches) click to toggle source
# File lib/git_commands/computer.rb, line 109
        def clean_and_exit(branches)
  remove_locals(branches)
  exit
end
enter_repo() { || ... } click to toggle source
# File lib/git_commands/computer.rb, line 95
        def enter_repo
  Dir.chdir(@repo) do
    align
    yield
  end
end
local_def() click to toggle source
# File lib/git_commands/computer.rb, line 114
        def local_def
  "#{@origin}/#{@default}"
end
print_branches() click to toggle source
rebase_with(branch = local_def) click to toggle source
# File lib/git_commands/computer.rb, line 88
        def rebase_with(branch = local_def)
  `git rebase #{branch}`
  return true unless @repo.locked?
  @repo.unlock
  error("Got conflicts, aborting rebase with #{branch}!")
end
remove_locals(branches = @branches) click to toggle source
# File lib/git_commands/computer.rb, line 102
        def remove_locals(branches = @branches)
  `git checkout #{@default}`
  branches.each do |branch|
    `git branch -D #{branch}`
  end
end