class GitPlus::Commands::Tag
A Git tag command wrapper.
Public Class Methods
new(shell: Open3)
click to toggle source
# File lib/git_plus/commands/tag.rb, line 10 def initialize shell: Open3 @shell = shell end
Public Instance Methods
call(*arguments)
click to toggle source
# File lib/git_plus/commands/tag.rb, line 14 def call(*arguments) = shell.capture3("git", "tag", *arguments) def exist?(version) = local?(version) || remote?(version) def last shell.capture3("git", "describe", "--abbrev=0", "--tags", "--always") .then { |stdout, _stderr, status| status.success? ? stdout.strip : "" } end def local? version call("--list", version).then do |stdout, _stderr, status| status.success? && stdout.match?(/\A#{version}\Z/) end end def push = shell.capture3("git", "push", "--tags") def remote? version shell.capture3("git", "ls-remote", "--tags", "origin", version) .then do |stdout, _stderr, status| status.success? && stdout.match?(%r(.+tags/#{version}\Z)) end end def sign(version, body = "") = create(version, body, %w[--sign]) def tagged? = call.then { |stdout, _stderr, status| status.success? && !stdout.empty? } def unsign(version, body = "") = create(version, body, %w[--no-sign]) private attr_reader :shell def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end
create(version, body, options = [])
click to toggle source
# File lib/git_plus/commands/tag.rb, line 48 def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end
exist?(version)
click to toggle source
# File lib/git_plus/commands/tag.rb, line 16 def exist?(version) = local?(version) || remote?(version) def last shell.capture3("git", "describe", "--abbrev=0", "--tags", "--always") .then { |stdout, _stderr, status| status.success? ? stdout.strip : "" } end def local? version call("--list", version).then do |stdout, _stderr, status| status.success? && stdout.match?(/\A#{version}\Z/) end end def push = shell.capture3("git", "push", "--tags") def remote? version shell.capture3("git", "ls-remote", "--tags", "origin", version) .then do |stdout, _stderr, status| status.success? && stdout.match?(%r(.+tags/#{version}\Z)) end end def sign(version, body = "") = create(version, body, %w[--sign]) def tagged? = call.then { |stdout, _stderr, status| status.success? && !stdout.empty? } def unsign(version, body = "") = create(version, body, %w[--no-sign]) private attr_reader :shell def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end end
last()
click to toggle source
# File lib/git_plus/commands/tag.rb, line 18 def last shell.capture3("git", "describe", "--abbrev=0", "--tags", "--always") .then { |stdout, _stderr, status| status.success? ? stdout.strip : "" } end
local?(version)
click to toggle source
# File lib/git_plus/commands/tag.rb, line 23 def local? version call("--list", version).then do |stdout, _stderr, status| status.success? && stdout.match?(/\A#{version}\Z/) end end
push(= shell.capture3("git", "push", "--tags"))
click to toggle source
# File lib/git_plus/commands/tag.rb, line 29 def push = shell.capture3("git", "push", "--tags") def remote? version shell.capture3("git", "ls-remote", "--tags", "origin", version) .then do |stdout, _stderr, status| status.success? && stdout.match?(%r(.+tags/#{version}\Z)) end end def sign(version, body = "") = create(version, body, %w[--sign]) def tagged? = call.then { |stdout, _stderr, status| status.success? && !stdout.empty? } def unsign(version, body = "") = create(version, body, %w[--no-sign]) private attr_reader :shell def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end end end
remote?(version)
click to toggle source
# File lib/git_plus/commands/tag.rb, line 31 def remote? version shell.capture3("git", "ls-remote", "--tags", "origin", version) .then do |stdout, _stderr, status| status.success? && stdout.match?(%r(.+tags/#{version}\Z)) end end
sign(version, body = "")
click to toggle source
# File lib/git_plus/commands/tag.rb, line 38 def sign(version, body = "") = create(version, body, %w[--sign]) def tagged? = call.then { |stdout, _stderr, status| status.success? && !stdout.empty? } def unsign(version, body = "") = create(version, body, %w[--no-sign]) private attr_reader :shell def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end end end end
tagged?(= call.then { |stdout, _stderr, status| status.success? && !stdout.empty? })
click to toggle source
# File lib/git_plus/commands/tag.rb, line 40 def tagged? = call.then { |stdout, _stderr, status| status.success? && !stdout.empty? } def unsign(version, body = "") = create(version, body, %w[--no-sign]) private attr_reader :shell def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end end end
unsign(version, body = "")
click to toggle source
# File lib/git_plus/commands/tag.rb, line 42 def unsign(version, body = "") = create(version, body, %w[--no-sign]) private attr_reader :shell def create version, body, options = [] fail Error, "Unable to create Git tag without version." unless version fail Error, "Tag exists: #{version}." if exist? version Tempfile.open Identity::NAME do |file| file.write body write version, file.tap(&:rewind), options end end def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end end
write(version, file, options = [])
click to toggle source
# File lib/git_plus/commands/tag.rb, line 58 def write version, file, options = [] arguments = ["--annotate", version, "--cleanup", "verbatim", *options, "--file", file.path] call(*arguments).then do |_stdout, _stderr, status| fail Error, "Unable to create tag: #{version}." unless status.success? end end