lib/git.rb in yac-1.3.2 vs lib/git.rb in yac-1.4.0

- old
+ new

@@ -1,41 +1,45 @@ class Git - def initialize(path) - @working_path = path - end + class << self + def clone(from,path) + system("git clone #{from} #{path}") + end - def self.clone(from,path,name) - `cd #{path} && git clone #{from} #{name}` - end + def init(path) + system("mkdir -p #{path}") + system("cd #{path} && git init") + end - def self.init(path) - `cd #{path} && git init` - end + 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 - def mv(orig,new,with_commit = true) - `cd '#@working_path' && git mv #{orig} #{new}` - self.commit("#{clean_name(orig)} Renamed to #{clean_name(new)}") if with_commit - end + 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 - def add(file,with_commit = true) - `cd '#@working_path' && git add '#{file}'` - self.commit("#{clean_name(file)} Added") if with_commit - end + def edit(file) + return rm(file) if File.zero?(file) + system("git add '#{file}'") + self.commit("#{cleanup_name(file)} Updated") + end - def edit(file,with_commit = true) - `cd '#@working_path' && git add '#{file}'` - self.commit("#{clean_name(file)} Updated") if with_commit - end + def rm(file) + system("git rm -f '#{file}'") + self.commit("#{cleanup_name(file)} Removed") + end - def rm(file,with_commit=true) - `cd '#@working_path' && git rm -f '#{file}'` - self.commit("#{clean_name(file)} Removed") if with_commit - end + def commit(msg,*args) + system("git commit #{args.to_s} -m '#{msg}' >/dev/null") + end - def commit(msg,*args) - `cd '#@working_path' && git commit #{args.to_s} -m '#{msg}'` - end - - def clean_name(f) - return f.sub(/^(.*)?\/(main|private)\/(.*)/,'\3').sub(/^@/,'') + def cleanup_name(f) + return f.sub(/^(.*)?\/(main|private)\/(.*)/,'\3').sub(/^@/,'') + end end end