Class: Git

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

Class Method Summary collapse

Class Method Details

.add(file) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/git.rb', line 18

def add(file)
  if File.exist?(file)
    return system("rm #{file}") if File.zero?(file)
    system("git add '#{file}'")
    self.commit("#{cleanup_name(file)} Added")
  end
end

.cleanup_name(f) ⇒ Object



41
42
43
# File 'lib/git.rb', line 41

def cleanup_name(f)
  return f.sub(/^(.*)?\/(main|private)\/(.*)/,'\3').sub(/^@/,'')
end

.clone(from, path) ⇒ Object



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

def clone(from,path)
  system("git clone #{from} #{path}")
end

.commit(msg, args = '') ⇒ Object



37
38
39
# File 'lib/git.rb', line 37

def commit(msg,args='')
  system("git commit #{args} -m '#{msg}' >/dev/null")
end

.edit(file) ⇒ Object



26
27
28
29
30
# File 'lib/git.rb', line 26

def edit(file)
  return rm(file) if File.zero?(file)
  system("git add '#{file}'")
  self.commit("#{cleanup_name(file)} Updated")
end

.init(path) ⇒ Object



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

def init(path)
  system("mkdir -p #{path}")
  system("cd #{path} && git init")
end

.mv(orig, new) ⇒ Object



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

def mv(orig,new)
  FileUtils.mkdir_p(File.dirname(new))
  system("git mv #{orig} #{new}")
  self.commit("#{cleanup_name(orig)} Renamed to #{cleanup_name(new)}")
end

.rm(file) ⇒ Object



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

def rm(file)
  system("git rm -f '#{file}'")
  self.commit("#{cleanup_name(file)} Removed")
end