Class: AgentsSkillVault::GitOperations
- Inherits:
-
Object
- Object
- AgentsSkillVault::GitOperations
- 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.
Constant Summary collapse
- MIN_VERSION =
Minimum required Git version for sparse checkout support
"2.25.0"
Class Method Summary collapse
-
.check_git_available! ⇒ void
Checks if git is installed and available in PATH.
-
.check_git_version! ⇒ void
Checks if the installed git version meets minimum requirements.
-
.clone_repo(url, target_path, branch: nil) ⇒ void
Clones a git repository.
-
.current_branch(path) ⇒ String
Gets the current branch name of a repository.
-
.pull(path) ⇒ void
Pulls the latest changes from the remote.
-
.sparse_checkout(url, target_path, branch:, paths:) ⇒ void
Performs a sparse checkout to clone only specific paths.
Class Method Details
.check_git_available! ⇒ void
This method returns an undefined value.
Checks if git is installed and available in PATH.
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.
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.
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.
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+).
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 |