Sha256: 6c51cb20ad392a6935cdd79b62a3adbb46843686c28b0c2777ba2bea64511c04

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 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 --sort=-v:refname "#{prefix}[0-9]*" 2> /dev/null`

      tags = output.split.collect do |tag|
        klass.parse(tag)
      end

      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.2 lib/git_bumper/git.rb
git_bumper-0.1.1 lib/git_bumper/git.rb