class Raykit::Git::Repository
Functionality to manage a remote git repository
def self.parse(json)
def self.parse(json) hash=JSON.parse(json) repo=Repository.new(hash["url"]) repo end
def branches
def branches results = Array.new update_local_clone_directory if(Dir.exist?(local_clone_directory)) Dir.chdir(local_clone_directory) do `git branch`.split('\n').each{|line| branch = line.gsub('*','').strip results.insert(-1,branch) if(branch.length > 0) } end end results end
def checkout_local_clone_directory_branch(branch)
def checkout_local_clone_directory_branch(branch) te_local_clone_directory ir.exist?(local_clone_directory)) Dir.chdir(local_clone_directory) do check=`git branch` if(!check.include?("* #{branch}")) t = `git checkout #{branch}` end check=`git branch` return check.include?("* #{branch}") end e
def clone(directory,depth=0)
def clone(directory,depth=0) if(depth == 0) PROJECT.run("git clone #{@url} #{directory}") else PROJECT.run("git clone #{@url} #{directory} --depth #{depth}") end end
def get_dev_dir(dir)
def get_dev_dir(dir) dev_dir=Environment::get_dev_dir(dir) return "#{dev_dir}/#{relative_path}" end
def initialize(url)
def initialize(url) @url=url @clone_directory = Raykit::Git::Directory.new(get_dev_dir('clone')) @work_directory = Raykit::Git::Directory.new(get_dev_dir('work')) end
def latest_commit(branch)
def latest_commit(branch) if(checkout_local_clone_directory_branch(branch)) text=`git log -n 1` scan=text.scan(/commit ([\w]+)\s/) return scan[0][0].to_s end '' end
def latest_tag(branch)
def latest_tag(branch) if(checkout_local_clone_directory_branch(branch)) return `git describe --abbrev=0`.strip end '' end
def local_clone_directory
def local_clone_directory e_dir="#{Environment::get_dev_dir('clone')}/#{relative_path}"
def relative_path
def relative_path @url.gsub('https://','').gsub('.git','').gsub('http://','') end
def to_json
def to_json JSON.generate({"url" => @url}) end
def update_local_clone_directory
def update_local_clone_directory ir.exist?(local_clone_directory)) Dir.chdir(local_clone_directory) do Raykit::Command.new('git pull') #t = `git pull` end PROJECT.run("git clone #{@url} #{local_clone_directory}")