Sha256: 5896370acf26d3a5254891666e0c7e3ef2af1298b7bbb08d8991472fc4a04d5b

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 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.pull
      if is_git_repo && !detached
        "git pull".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.35 lib/makit/git.rb
makit-0.0.34 lib/makit/git.rb
makit-0.0.33 lib/makit/git.rb
makit-0.0.32 lib/makit/git.rb
makit-0.0.31 lib/makit/git.rb