Class: TreeishExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/treeish_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git: nil) ⇒ TreeishExtractor

Returns a new instance of TreeishExtractor.



9
10
11
# File 'lib/treeish_extractor.rb', line 9

def initialize(git: nil)
  @git = git || Git.open(Dir.pwd)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



7
8
9
# File 'lib/treeish_extractor.rb', line 7

def git
  @git
end

Instance Method Details

#recent_branch_namesObject



24
25
26
27
28
29
30
31
32
# File 'lib/treeish_extractor.rb', line 24

def recent_branch_names
  # TODO limit number of branches when arg is not given
  cmd = 'git branch --sort=-committerdate'
  # a current branch is prefixed with '* ' to indicate it's selected
  selecting_rule = ->(line, names) do
    names << line.strip.sub('* ', '') unless line =~ /HEAD detached/
  end
  get_treeish_names(cmd, selecting_rule)
end

#recent_tag_namesObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/treeish_extractor.rb', line 13

def recent_tag_names
  # TODO unlimit number of tags when arg is given
  # cmd = "git describe --tags $(git rev-list --tags --max-count=1000)"
  cmd = 'git tag --sort=-committerdate'
  # reject commits without an annotated tag
  selecting_rule = ->(line, names) do
    names << line.strip
  end
  get_treeish_names(cmd, selecting_rule)
end