Sha256: d71a410fd95945c8a6cbd0a07aeff447efe9948ae3b76edda15ad75eeecd2a25

Contents?: true

Size: 942 Bytes

Versions: 2

Compression:

Stored size: 942 Bytes

Contents

module GitBumper
  # This module has some functions to deal with a git repository.
  module Git
    module_function

    # Returns true if the current working directory has a git repository.
    #
    # @return [Boolean]
    def repo?
      system('git rev-parse --is-inside-work-tree >/dev/null 2>&1')
    end

    # Fetches all git tags.
    def fetch_tags
      system('git fetch --tags >/dev/null 2>&1')
    end

    # Returns the greatest tag.
    def greatest_tag(prefix: 'v', klass: Tag)
      output = `git tag --list 2> /dev/null`

      tags = output
        .split
        .map { |t| klass.parse(t) }
        .select { |t| t && t.prefix == prefix }
        .sort
        .reverse

      tags.find do |tag|
        tag
      end || false
    end

    # Create a new git tag.
    def create_tag(tag)
      `git tag #{tag}`
    end

    # Pushes a tag to origin.
    def push_tag(tag)
      `git push origin #{tag}`
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_bumper-0.1.4 lib/git_bumper/git.rb
git_bumper-0.1.3 lib/git_bumper/git.rb