Class: Worktree::Command::CheckStale

Inherits:
Object
  • Object
show all
Defined in:
lib/worktree/command/check_stale.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_dir:) ⇒ CheckStale

Returns a new instance of CheckStale.



6
7
8
# File 'lib/worktree/command/check_stale.rb', line 6

def initialize(project_dir:)
  @project_dir = File.expand_path project_dir || Dir.pwd
end

Instance Method Details

#do!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/worktree/command/check_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).
             select { |f| File.directory?("#{@project_dir}/#{f}}") }.
             reject { |f| ['master', '.', '..'].include?(f) }

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

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