class Worktree::Command::RemoveStale

Public Class Methods

new(project_dir:) click to toggle source
# File lib/worktree/command/remove_stale.rb, line 6
def initialize(project_dir:)
  @project_dir = File.expand_path project_dir || Dir.pwd
end

Public Instance Methods

do!() click to toggle source
# File lib/worktree/command/remove_stale.rb, line 10
def do!
  # update refs
  git.remotes.each { |remote| git.fetch(remote, prune: true) }
  git.pull('upstream', 'master')

  branches = Dir.entries(@project_dir).
    reject { |d| d == '.' || d == '..' || d == 'master' }.
    select { |f| File.directory?(f) }

  stale_branches = branches.select do |branch|
    git.branch('master').contains?(branch)
  end

  Worktree.logger.info { "You have #{stale_branches.size} stale branches!" }

  stale_branches.each_with_index do |stale_branch, index|
    Worktree.logger.info { "#{index + 1} of #{stale_branches.size}" }
    Remove.new(stale_branch, project_dir: @project_dir, update_refs: false).do!
  end
end

Private Instance Methods

git() click to toggle source
# File lib/worktree/command/remove_stale.rb, line 33
def git
  @git ||= Worktree.git_for(@project_dir)
end