Class: Git

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

Class Method Summary collapse

Class Method Details

.branch(directory = '') ⇒ Object



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

def self.branch directory=''
    directory=Dir.pwd if directory.length == 0
    Dir.chdir(directory) do
		begin
		  `git branch`.scan(/\* ([.\w-]+)/)[0][0] if(File.exists?('.git'))
	    rescue
	    	''
	    end
    end
end

.has_changes?(directory = '') ⇒ Boolean

Returns:

  • (Boolean)


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

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
end

.init(directory = '') ⇒ Object



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

def self.init directory=''
    directory=Dir.pwd if directory.length==0
    FileUtils.mkpath directory if !File.exists?(directory)
    if(!File.exists?("#{directory}/.git"))
        Dir.chdir(directory) do
           `git init`
           File.open('.gitignore','w'){|f|
               f.puts '### Mac ###'
               f.puts '*.DS_Store'
           }
           `git add .gitignore`
           `git commit -m'added .gitignore'`
        end
    end
end

.remote_origin(directory = '') ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/git.rb', line 13

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] if(File.exists?('.git'))
		rescue
			url=''
		end
	end
	url
end