Class: Git

Inherits:
Object
  • Object
show all
Defined in:
lib/forgetful-git/common/git.rb

Class Method Summary collapse

Class Method Details

.amnesia_maxObject



14
15
16
17
18
19
20
21
# File 'lib/forgetful-git/common/git.rb', line 14

def self.amnesia_max
    count = `git config amnesia.count`.trim.to_i
    if $?.exitstatus == 0
        count
    else
        @amnesia_count_default
    end
end

.author_nameObject



23
24
25
# File 'lib/forgetful-git/common/git.rb', line 23

def self.author_name
    `git config user.name`.trim
end

.compared_to_origin(status) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/forgetful-git/common/git.rb', line 46

def self.compared_to_origin(status)
    if status[0].include? "[behind"
        "behind"
    elsif status[0].include? "[ahead"
        "ahead"
    end
end

.logs(repos) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/forgetful-git/common/git.rb', line 54

def self.logs(repos)
    logs = []
    repos.each do |repo|
    cmd = "cd '#{repo}' 2>/dev/null" +
        " && git log --max-count=#{Git.amnesia_max} --author='#{Git.author_name}'" +
        " --pretty=format:'%at::#{repo.basename}::%s' 2>/dev/null"
        log = `#{cmd}`
        if $?.exitstatus == 0
            logs += log.explode.map { |l| Log.new(l) }
        end
    end
    logs
end

.other_dirsObject



10
11
12
# File 'lib/forgetful-git/common/git.rb', line 10

def self.other_dirs
    `git config dir.others | envsubst`.split_dir.explode
end

.reposObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/forgetful-git/common/git.rb', line 27

def self.repos
    workspace = Git.workspace
    repos = Git.other_dirs
    if !workspace.empty?
        repos += `ls #{workspace}`.explode.map do |r|
            r.prepend("#{workspace}/")
        end
    end
    repos
end

.status(repo) ⇒ Object



42
43
44
# File 'lib/forgetful-git/common/git.rb', line 42

def self.status(repo)
    `cd "#{repo}" && git status -s 2>/dev/null`.explode
end

.update(repo) ⇒ Object



38
39
40
# File 'lib/forgetful-git/common/git.rb', line 38

def self.update(repo)
    `cd "#{repo}" && git fetch >/dev/null 2>/dev/null`
end

.workspaceObject



6
7
8
# File 'lib/forgetful-git/common/git.rb', line 6

def self.workspace
    `git config dir.workspace | envsubst`.trim
end