Class: AgentsSkillVault::GitOperations

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

Overview

Provides Git operations for cloning, syncing, and managing repositories.

All methods are class methods that execute git commands via the shell. Requires Git 2.25.0+ for sparse checkout support.

Examples:

Clone a repository

GitOperations.clone_repo("https://github.com/user/repo", "/path/to/target")

Sparse checkout for a specific folder

GitOperations.sparse_checkout(
  "https://github.com/user/repo",
  "/path/to/target",
  branch: "main",
  paths: ["lib/skills"]
)

Constant Summary collapse

MIN_VERSION =

Minimum required Git version for sparse checkout support

"2.25.0"

Class Method Summary collapse

Class Method Details

.check_git_available!void

This method returns an undefined value.

Checks if git is installed and available in PATH.

Raises:



33
34
35
36
37
# File 'lib/agents_skill_vault/git_operations.rb', line 33

def check_git_available!
  return if git_installed?

  raise Errors::GitNotInstalled, "Git is not installed or not available in PATH"
end

.check_git_version!void

This method returns an undefined value.

Checks if the installed git version meets minimum requirements.

Raises:



44
45
46
47
48
49
# File 'lib/agents_skill_vault/git_operations.rb', line 44

def check_git_version!
  version = git_version
  return unless version < Gem::Version.new(MIN_VERSION)

  raise Errors::GitVersion, "Git version #{version} is too old. Minimum required: #{MIN_VERSION}"
end

.clone_repo(url, target_path, branch: nil) ⇒ void

This method returns an undefined value.

Clones a git repository.

Examples:

Clone with default branch

GitOperations.clone_repo("https://github.com/user/repo", "/local/path")

Clone specific branch

GitOperations.clone_repo("https://github.com/user/repo", "/local/path", branch: "develop")

Raises:

  • (Error)

    if the clone command fails



65
66
67
68
# File 'lib/agents_skill_vault/git_operations.rb', line 65

def clone_repo(url, target_path, branch: nil)
  branch_flag = branch ? "--branch #{branch}" : ""
  run_command("git clone #{branch_flag} #{url} #{target_path}")
end

.current_branch(path) ⇒ String

Gets the current branch name of a repository.



121
122
123
124
125
126
# File 'lib/agents_skill_vault/git_operations.rb', line 121

def current_branch(path)
  Dir.chdir(path) do
    stdout, = run_command("git branch --show-current")
    stdout.strip
  end
end

.pull(path) ⇒ void

This method returns an undefined value.

Pulls the latest changes from the remote.

Performs a fetch and hard reset to match the remote branch.

Raises:

  • (Error)

    if the pull command fails



109
110
111
112
113
114
# File 'lib/agents_skill_vault/git_operations.rb', line 109

def pull(path)
  Dir.chdir(path) do
    run_command("git fetch origin")
    run_command("git reset --hard origin/$(git branch --show-current)")
  end
end

.sparse_checkout(url, target_path, branch:, paths:) ⇒ void

This method returns an undefined value.

Performs a sparse checkout to clone only specific paths.

Uses modern git sparse-checkout commands to download only the specified directories or files from the repository (requires Git 2.25.0+).

Examples:

Checkout a single folder

GitOperations.sparse_checkout(
  "https://github.com/user/repo",
  "/local/path",
  branch: "main",
  paths: ["lib/skills/my-skill"]
)

Raises:

  • (Error)

    if any git command fails



90
91
92
93
94
95
96
97
98
99
# File 'lib/agents_skill_vault/git_operations.rb', line 90

def sparse_checkout(url, target_path, branch:, paths:)
  run_command("git init #{target_path}")
  Dir.chdir(target_path) do
    run_command("git remote add origin #{url}")
    run_command("git sparse-checkout init --no-cone")
    run_command("git sparse-checkout set #{paths.join(" ")}")
    run_command("git fetch origin #{branch}")
    run_command("git checkout #{branch}")
  end
end