Sha256: 217bfe9bebe5dc384784b9cac2253d9af5bc08e1668ecbef25e4ae31e230295f

Contents?: true

Size: 852 Bytes

Versions: 34

Compression:

Stored size: 852 Bytes

Contents

module Git
  # object that holds all the available worktrees
  class Worktrees

    include Enumerable

    def initialize(base)
      @worktrees = {}

      @base = base

      # Array contains [dir, git_hash]
      @base.lib.worktrees_all.each do |w|
        @worktrees[w[0]] = Git::Worktree.new(@base, w[0], w[1])
      end
    end

    # array like methods

    def size
      @worktrees.size
    end

    def each(&block)
      @worktrees.values.each(&block)
    end

    def [](worktree_name)
      @worktrees.values.inject(@worktrees) do |worktrees, worktree|
        worktrees[worktree.full] ||= worktree
        worktrees
      end[worktree_name.to_s]
    end

    def to_s
      out = ''
      @worktrees.each do |k, b|
        out << b.to_s << "\n"
      end
      out
    end

    def prune
      @base.lib.worktree_prune
    end
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
git-2.3.3 lib/git/worktrees.rb
git-2.3.2 lib/git/worktrees.rb
git-2.3.1 lib/git/worktrees.rb
git-2.3.0 lib/git/worktrees.rb
git-2.2.0 lib/git/worktrees.rb
git-2.1.1 lib/git/worktrees.rb
git-2.1.0 lib/git/worktrees.rb
git-2.0.0.pre3 lib/git/worktrees.rb
git-2.0.0.pre2 lib/git/worktrees.rb
git-2.0.0.pre1 lib/git/worktrees.rb
git-1.19.1 lib/git/worktrees.rb
git-1.19.0 lib/git/worktrees.rb
git-1.18.0 lib/git/worktrees.rb
git-1.17.2 lib/git/worktrees.rb
git-1.17.1 lib/git/worktrees.rb
git-1.17.0 lib/git/worktrees.rb
git-1.16.0 lib/git/worktrees.rb
git-1.15.0 lib/git/worktrees.rb
git-1.14.0 lib/git/worktrees.rb
git-1.13.2 lib/git/worktrees.rb