Sha256: 865e1ed71b7e63fd42f705e020709d4306e96bfb02c6e90121336d02dc5cb188

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 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.get_file_infos()
      file_infos = []
      command = `git ls-files`
      command.split("\n").map do |path|
        begin
          file_infos << FileInfo.new(name: path, mtime: File.mtime(path), size: File.size(path))
        rescue
          next
        end
      end
      file_infos.sort_by! { |info| info.mtime }.reverse!
      file_infos
    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

5 entries across 5 versions & 1 rubygems

Version Path
makit-0.0.26 lib/makit/git.rb
makit-0.0.25 lib/makit/git.rb
makit-0.0.24 lib/makit/git.rb
makit-0.0.23 lib/makit/git.rb
makit-0.0.22 lib/makit/git.rb