lib/makit/git.rb in makit-0.0.35 vs lib/makit/git.rb in makit-0.0.36

- old
+ new

@@ -1,86 +1,86 @@ -# 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 +# 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