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
- #delete_local(version) ⇒ Object
- #delete_remote(version) ⇒ 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 |
#delete_local(version) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/gitt/commands/tag.rb', line 48 def delete_local(version, *, **) call("--delete", version, *, **).fmap { |text| text[/\d+\.\d+\.\d+/] } .alt_map do |error| error.delete_prefix("error: tag ").chomp end end |
#delete_remote(version) ⇒ Object
55 56 57 58 59 |
# File 'lib/gitt/commands/tag.rb', line 55 def delete_remote(version, *, **) shell.call("push", "--delete", "origin", version, *, **) .fmap { version } .alt_map { |error| error.gsub("error: ", "").chomp } end |
#exist?(version) ⇒ Boolean
61 |
# File 'lib/gitt/commands/tag.rb', line 61 def exist?(version) = local?(version) || remote?(version) |
#index(*arguments) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/gitt/commands/tag.rb', line 63 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
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gitt/commands/tag.rb', line 70 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
82 83 84 |
# File 'lib/gitt/commands/tag.rb', line 82 def local? version call("--list", version).value_or(Core::EMPTY_STRING).match?(/\A#{version}\Z/) end |
#push ⇒ Object
86 |
# File 'lib/gitt/commands/tag.rb', line 86 def push(*, **) = shell.call("push", "--tags", *, **) |
#remote?(version) ⇒ Boolean
88 89 90 91 92 |
# File 'lib/gitt/commands/tag.rb', line 88 def remote? version shell.call("ls-remote", "--tags", "origin", version) .value_or(Core::EMPTY_STRING) .match?(%r(.+tags/#{version}\Z)) end |
#show(version) ⇒ Object
94 95 96 |
# File 'lib/gitt/commands/tag.rb', line 94 def show(version, *, **) call(pretty_format, "--list", version, *, **).fmap { |content| parser.call content } end |
#tagged? ⇒ Boolean
98 |
# File 'lib/gitt/commands/tag.rb', line 98 def tagged? = !call.value_or(Core::EMPTY_STRING).empty? |