Class: Gitt::Commands::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/gitt/commands/tag.rb

Overview

A Git tag command wrapper.

Constant Summary collapse

KEY_MAP =
{
  author_email: "%(*authoremail)",
  author_name: "%(*authorname)",
  authored_at: "%(*authordate:raw)",
  authored_relative_at: "%(*authordate:relative)",
  body: "%(body)",
  committed_at: "%(*committerdate:raw)",
  committed_relative_at: "%(*committerdate:relative)",
  committer_email: "%(*committeremail)",
  committer_name: "%(*committername)",
  sha: "%(objectname)",
  signature: "%(contents:signature)",
  subject: "%(subject)",
  trailers: "%(trailers)",
  version: "%(refname)"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(shell: SHELL, key_map: KEY_MAP, parser: Parsers::Tag.new) ⇒ Tag

Returns a new instance of Tag.



30
31
32
33
34
# File 'lib/gitt/commands/tag.rb', line 30

def initialize shell: SHELL, key_map: KEY_MAP, parser: Parsers::Tag.new
  @shell = shell
  @key_map = key_map
  @parser = parser
end

Instance Method Details

#callObject



36
# File 'lib/gitt/commands/tag.rb', line 36

def call(*) = shell.call("tag", *)

#create(version, body = Core::EMPTY_STRING, *flags) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/gitt/commands/tag.rb', line 38

def create version, body = Core::EMPTY_STRING, *flags
  return Failure "Unable to create Git tag without version." unless version
  return Failure "Tag exists: #{version}." if exist? version

  Tempfile.open "gitt" do |file|
    file.write body
    write version, file.tap(&:rewind), *flags
  end
end

#exist?(version) ⇒ Boolean

Returns:

  • (Boolean)


48
# File 'lib/gitt/commands/tag.rb', line 48

def exist?(version) = local?(version) || remote?(version)

#index(*arguments) ⇒ Object



50
51
52
53
54
55
# File 'lib/gitt/commands/tag.rb', line 50

def index *arguments
  arguments.prepend(pretty_format, "--list")
           .then { |flags| call(*flags) }
           .fmap { |content| String(content).scrub("?").split %("\n") }
           .fmap { |entries| build_records entries }
end

#lastObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gitt/commands/tag.rb', line 57

def last
  shell.call("describe", "--abbrev=0", "--tags")
       .fmap(&:strip)
       .or do |error|
         if error.match?(/no names found/i)
           Failure "No tags found."
         else
           Failure error.delete_prefix("fatal: ").chomp
         end
       end
end

#local?(version) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/gitt/commands/tag.rb', line 69

def local? version
  call("--list", version).value_or(Core::EMPTY_STRING).match?(/\A#{version}\Z/)
end

#pushObject



73
# File 'lib/gitt/commands/tag.rb', line 73

def push = shell.call "push", "--tags"

#remote?(version) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
# File 'lib/gitt/commands/tag.rb', line 75

def remote? version
  shell.call("ls-remote", "--tags", "origin", version)
       .value_or(Core::EMPTY_STRING)
       .match?(%r(.+tags/#{version}\Z))
end

#show(version) ⇒ Object



81
82
83
# File 'lib/gitt/commands/tag.rb', line 81

def show version
  call(pretty_format, "--list", version).fmap { |content| parser.call content }
end

#tagged?Boolean

Returns:

  • (Boolean)


85
# File 'lib/gitt/commands/tag.rb', line 85

def tagged? = !call.value_or(Core::EMPTY_STRING).empty?