Sha256: 515417f7593e565f30cb55aa2401c564ae6cad8cb42c40b17b8c3365406c74c8

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

# This module provides classes for the Makit gem.
module Makit
  # This class provide methods for working with the system Environment.
  #
  class Git
    def self.is_git_repo
      Dir.exist? ".git"
    end

    def self.detached
      `git status`.include?("detached")
    end

    def self.is_read_only
      !is_git_repo || detached
    end

    def self.is_clean
      `git status --porcelain`.empty?
    end

    def self.integrate
      if is_git_repo && !detached
        "git add .".run
        "git commit -m \"integrate\"".run unless is_clean
      end
    end

    def self.sync
      if is_git_repo && !detached
        "git pull".try
        "git push origin".try
      end
    end

    def self.zip_source_files(zipfilename)
      "git archive --format zip --output #{zipfilename} HEAD".run
    end

    def self.branch
      `git branch --show-current`.strip
    end

    def self.commitsha
      `git rev-parse HEAD`.strip
    end

    def self.commitmsg
      `git log -1 --pretty=%B`.strip
    end

    def self.commitdate
      `git log -1 --pretty=%cd`.strip
    end

    def self.commitauthor
      `git log -1 --pretty=%an`.strip
    end

    def self.commitemail
      `git log -1 --pretty=%ae`.strip
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
makit-0.0.5 lib/makit/git.rb
makit-0.0.4 lib/makit/git.rb
makit-0.0.3 lib/makit/git.rb
makit-0.0.2 lib/makit/git.rb