Class: Gitt::Commands::Tag
- Inherits:
-
Object
- Object
- Gitt::Commands::Tag
- 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
- #call ⇒ Object
- #create(version, body = Core::EMPTY_STRING, *flags) ⇒ Object
- #exist?(version) ⇒ Boolean
- #index(*arguments) ⇒ Object
-
#initialize(shell: SHELL, key_map: KEY_MAP, parser: Parsers::Tag.new) ⇒ Tag
constructor
A new instance of Tag.
- #last ⇒ Object
- #local?(version) ⇒ Boolean
- #push ⇒ Object
- #remote?(version) ⇒ Boolean
- #show(version) ⇒ Object
- #tagged? ⇒ Boolean
Constructor Details
Instance Method Details
#call ⇒ Object
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
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 |
#last ⇒ Object
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
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 |
#push ⇒ Object
73 |
# File 'lib/gitt/commands/tag.rb', line 73 def push = shell.call "push", "--tags" |
#remote?(version) ⇒ 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
85 |
# File 'lib/gitt/commands/tag.rb', line 85 def tagged? = !call.value_or(Core::EMPTY_STRING).empty? |