Class: Git

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

Class Method Summary collapse

Class Method Details

.branchObject



2
3
4
5
6
7
8
# File 'lib/git.rb', line 2

def self.branch
		begin
`git branch`.scan(/\* ([.\w-]+)/)[0][0]
 rescue
 	''
 end
end

.has_changes?(directory = '') ⇒ Boolean



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/git.rb', line 23

def self.has_changes? directory=''
    directory=Dir.pwd if directory.length==0
    Dir.chdir(directory) do
        if(File.exists?('.git'))
            return true if `git status`.include?('modified:')
        end
    end
    false
    # $ git status
    # On branch master
    # nothing to commit, working directory clean

    # $ git status
    # On branch master
    # Changes not staged for commit:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   modified:   lib/git.rb
    #
    # no changes added to commit (use "git add" and/or "git commit -a")

end

.remote_origin(directory = '') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/git.rb', line 10

def self.remote_origin directory=''
	url=''
	directory=Dir.pwd if directory.length == 0
	Dir.chdir(directory) do
		begin
			url=`git remote show origin`.scan(/Fetch URL: ([\.\-:\/\w\d]+)/)[0][0]
		rescue
			url=''
		end
	end
	url
end