Class: Makit::Git::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/git/repository.rb

Overview

This class provides methods for querying git repository state and metadata.

Class Method Summary collapse

Class Method Details

.branchObject



61
62
63
# File 'lib/makit/git/repository.rb', line 61

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

.ci?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/makit/git/repository.rb', line 12

def self.ci?
  ENV["CI"] == "true"
end

.clean?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/makit/git/repository.rb', line 24

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

.commitauthorObject



77
78
79
# File 'lib/makit/git/repository.rb', line 77

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

.commitdateObject



73
74
75
# File 'lib/makit/git/repository.rb', line 73

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

.commitemailObject



81
82
83
# File 'lib/makit/git/repository.rb', line 81

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

.commitmsgObject



69
70
71
# File 'lib/makit/git/repository.rb', line 69

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

.commitshaObject



65
66
67
# File 'lib/makit/git/repository.rb', line 65

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

.detachedObject



16
17
18
# File 'lib/makit/git/repository.rb', line 16

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

.get_file_infosObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/makit/git/repository.rb', line 36

def self.get_file_infos
  file_infos = []
  file_list = `git ls-files`.split("\n")
  # iterate over the filelist and get the file infos
  file_list.each do |file|
    file_infos << FileInfo.new(name: file, mtime: File.mtime(file), size: File.size(file))
  rescue StandardError
    next
  end
  file_infos.sort_by!(&:mtime).reverse!
  file_infos
end

.get_remote_urlObject



85
86
87
# File 'lib/makit/git/repository.rb', line 85

def self.get_remote_url
  `git remote get-url origin`.strip
end

.get_untracked_file_infosObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/makit/git/repository.rb', line 49

def self.get_untracked_file_infos
  file_infos = []
  file_list = `git ls-files --others --exclude-standard`.split("\n")
  file_list.each do |file|
    file_infos << FileInfo.new(name: file, mtime: File.mtime(file), size: File.size(file))
  rescue StandardError
    next
  end
  file_infos.sort_by!(&:mtime).reverse!
  file_infos
end

.git_repo?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/makit/git/repository.rb', line 8

def self.git_repo?
  Dir.exist? ".git"
end

.read_only?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/makit/git/repository.rb', line 20

def self.read_only?
  !git_repo? || detached
end

.unstaged_filesObject



28
29
30
# File 'lib/makit/git/repository.rb', line 28

def self.unstaged_files
  `git status --porcelain`.split("\n")
end

.untracked_filesObject



32
33
34
# File 'lib/makit/git/repository.rb', line 32

def self.untracked_files
  `git ls-files --others --exclude-standard`.split("\n")
end