Class: Raykit::Git

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#start_timeObject

Returns the value of attribute start_time.



3
4
5
# File 'lib/raykit/git.rb', line 3

def start_time
  @start_time
end

Class Method Details

.add_remoteObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/raykit/git.rb', line 46

def self.add_remote
    remote = get_remote
    if(remote.length > 0)
    #if(Dir.exist?('.git'))

        #cmd = Command.new

        #cmd.command = 'git config --get remote.origin.url'

        #cmd.run

        #remote = cmd.output.strip

        remote_urls_copy = remote_urls
        if(!remote_urls_copy.include?(remote))
            remote_urls_copy.insert(0,remote)
            Git::remote_urls = remote_urls_copy
        end
    end
end

.branchObject



5
6
7
8
# File 'lib/raykit/git.rb', line 5

def self.branch
    branches = `git branch`
    branches.match(/ ([\w.]+)/).captures[0]
end

.get_remoteObject



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

def self.get_remote
    if(Dir.exist?('.git'))
        cmd = Command.new
        cmd.command = 'git config --get remote.origin.url'
        cmd.run
        return cmd.output.strip
    else
        ``
    end
end

.last_tagObject



10
11
12
# File 'lib/raykit/git.rb', line 10

def self.last_tag
    `git describe --abbrev=0 --tags`.strip
end

.list_remotesObject



78
79
80
# File 'lib/raykit/git.rb', line 78

def self.list_remotes
    remote_urls.each{|url| puts url}
end

.outstanding_commitObject



28
29
30
31
32
33
34
# File 'lib/raykit/git.rb', line 28

def self.outstanding_commit
    if(Git::user_can_commit)
        return !`git status`.include?('nothing to commit,')
    else
        return false
    end
end

.remote_urlsObject



62
63
64
65
66
67
68
69
# File 'lib/raykit/git.rb', line 62

def self.remote_urls
    filename="#{Environment::log_dir}/Raykit.Git.RemoteUrls.json";
    if(File.exist?(filename))
        JSON.parse(File.read(filename))
    else
        Array.new
    end
end

.remote_urls=(urls) ⇒ Object



71
72
73
74
75
76
# File 'lib/raykit/git.rb', line 71

def self.remote_urls=(urls)
    filename="#{Environment::log_dir}/Raykit.Git.RemoteUrls.json"
    File.open(filename,'w'){|f|
        f.write(JSON.generate(urls))
    }
end

.scan_remote_urlsObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/raykit/git.rb', line 82

def self.scan_remote_urls
    remotes = Array.new
    git_dirs = Array.new
    Dir.chdir(Environment::work_dir) do
        Dir.glob('**/.git'){|git_dir|
            dir = File.expand_path('..',git_dir)
            if(dir.length > 0)
                git_dirs.insert(0,dir)
            end
            
        }
    end

    git_dirs.each{|git_dir|
        Dir.chdir(git_dir) do
            remote = get_remote
            if(remote.length > 0)
                remotes.insert(0,remote)
            end
        end
    }
    remotes
end

.user_can_commitObject



22
23
24
25
26
# File 'lib/raykit/git.rb', line 22

def self.user_can_commit
    return false if(user_name.length == 0)
    return false if(user_email.length == 0)
    return true
end

.user_emailObject



18
19
20
# File 'lib/raykit/git.rb', line 18

def self.user_email
    return `git config --get user.email`.strip
end

.user_nameObject



14
15
16
# File 'lib/raykit/git.rb', line 14

def self.user_name
    return `git config --get user.name`.strip
end