class Raykit::Git::Repository

Functionality to manage a remote git repository

def self.make(url, commit_id, command)

def self.make(url, commit_id, command)
  repo = Raykit::Git::Repository.new(url)
  make_dir = repo.get_dev_dir("make") + "/" + commit_id
  FileUtils.mkdir_p(repo.get_dev_dir("make")) if !Dir.exists?(repo.get_dev_dir("make"))
  if (Dir.exists?(make_dir))
    FileUtils.rm_rf(make_dir)
  end
  run("git clone #{url} #{make_dir}")
  cmd = 0
  Dir.chdir(make_dir) do
    run("git reset --hard #{commit_id}")
    FileUtils.rm_rf(".git")
    cmd = Raykit::Command.new(command)
    cmd = cmd.run().summary().details_on_failure
  end
  FileUtils.rm_rf(make_dir) if (cmd.exitstatus == 0)
  cmd
end

def self.parse(json)

def self.parse(json)
  hash = JSON.parse(json)
  Repository.new(hash["url"])
end

def self.work(url, cmd)

def self.work(url, cmd)
  repo = Raykit::Git::Repository.new(url)
  work_dir = repo.get_dev_dir("work")
  repo.clone(work_dir) if !Dir.exist?(work_dir)
  Dir.chdir(work_dir) do
    run("git pull")
    #run(cmd)

    cmd = Raykit::Command.new(cmd)
    cmd = cmd.run().summary().details_on_failure
    cmd
  end
end

def self.work_integrate(url)

def self.work_integrate(url)
  repo = Raykit::Git::Repository.new(url)
  work_dir = repo.get_dev_dir("work")
  repo.clone(work_dir) if !Dir.exist?(work_dir)
  Dir.chdir(work_dir) do
    run("git pull")
    run("rake integrate")
  end
end

def self.work_pull(url)

def self.work_pull(url)
  repo = Raykit::Git::Repository.new(url)
  work_dir = repo.get_dev_dir("work")
  repo.clone(work_dir) if !Dir.exist?(work_dir)
  Dir.chdir(work_dir) do
    run("git pull")
  end
end

def branches

The branches for the git repository
def branches
  results = []
  update_local_clone_directory
  if Dir.exist?(local_clone_directory)
    Dir.chdir(local_clone_directory) do
      `git branch`.split('\n').each do |line|
        branch = line.gsub("*", "").strip
        results.insert(-1, branch) if branch.length.positive?
      end
    end
  end
  results
end

def checkout_local_clone_directory_branch(branch)

def checkout_local_clone_directory_branch(branch)
_local_clone_directory
.exist?(local_clone_directory)
chdir(local_clone_directory) do
eck = `git branch`
= `git checkout #{branch}` unless check.include?("* #{branch}")
eck = `git branch`
turn check.include?("* #{branch}")

def clone(directory, depth = 0)

Clone the repository to a specific directory
def clone(directory, depth = 0)
  if depth.zero?
    PROJECT.run("git clone #{@url} #{directory}")
  else
    PROJECT.run("git clone #{@url} #{directory} --depth #{depth}")
  end
end

def default_branch

default branch
def default_branch
  update_local_clone_directory
  if Dir.exist?(local_clone_directory)
    Dir.chdir(local_clone_directory) do
      # refs/remotes/origin/master

      default_branch = `git symbolic-ref refs/remotes/origin/HEAD`.split("/").last.strip
      return default_branch
    end
  end
  "main"
end

def get_dev_dir(dir)

def get_dev_dir(dir)
  dev_dir = Environment.get_dev_dir(dir)
  "#{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)

The latest commit id for a branch of the repostiory
def latest_commit(branch)
  if checkout_local_clone_directory_branch(branch)
    update_local_clone_directory
    Dir.chdir(local_clone_directory) do
      text = `git log -n 1`
      scan = text.scan(/commit (\w+)\s/)
      return scan[0][0].to_s
    end
  end
  ""
end

def latest_tag(branch)

The latest tag for a branch of the repository
def latest_tag(branch)
  return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch)
  ""
end

def local_clone_directory

def local_clone_directory
dir = "#{Environment.get_dev_dir("clone")}/#{relative_path}"

def relative_path

The relative path is a valid local path name derived from the url
def relative_path
  @url.gsub("https://", "").gsub(".git", "").gsub("http://", "")
end

def short_name()

def short_name()
  @url.split("/").last.gsub(".git", "")
end

def to_json(*_args)

def to_json(*_args)
  JSON.generate({ "url" => @url })
end

def update_local_clone_directory

def update_local_clone_directory
r.exist?(local_clone_directory)
.chdir(local_clone_directory) do
ull = Raykit::Command.new("git pull")
ull.run
ull
 t = `git pull`


JECT.run("git clone #{@url} #{local_clone_directory}")