Class: AgentC::Utils::Git
- Inherits:
-
Object
- Object
- AgentC::Utils::Git
- Defined in:
- lib/agent_c/utils/git.rb
Overview
Git utility class for managing Git operations in worktrees
Instance Attribute Summary collapse
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Instance Method Summary collapse
- #clean? ⇒ Boolean
- #commit_all(message) ⇒ Object
- #create_worktree(dir:, branch:, revision:) ⇒ Object
- #diff ⇒ Object
- #fixup_commit(revision) ⇒ Object
-
#initialize(repo_path) ⇒ Git
constructor
A new instance of Git.
- #last_revision ⇒ Object
- #reset_hard_all ⇒ Object
- #uncommitted_changes? ⇒ Boolean
Constructor Details
#initialize(repo_path) ⇒ Git
Returns a new instance of Git.
11 12 13 |
# File 'lib/agent_c/utils/git.rb', line 11 def initialize(repo_path) @repo_path = repo_path end |
Instance Attribute Details
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
9 10 11 |
# File 'lib/agent_c/utils/git.rb', line 9 def repo_path @repo_path end |
Instance Method Details
#clean? ⇒ Boolean
55 56 57 |
# File 'lib/agent_c/utils/git.rb', line 55 def clean? !uncommitted_changes? end |
#commit_all(message) ⇒ Object
41 42 43 44 |
# File 'lib/agent_c/utils/git.rb', line 41 def commit_all() shell.run!("cd #{repo_path} && git add --all && git commit --no-gpg-sign -m #{Shellwords.escape()}") last_revision end |
#create_worktree(dir:, branch:, revision:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/agent_c/utils/git.rb', line 15 def create_worktree(dir:, branch:, revision:) # Prune any stale worktrees first shell.run!("cd #{repo_path} && git worktree prune") # Remove worktree at dir if it exists (don't fail if it doesn't exist) shell.run!("cd #{repo_path} && (git worktree remove #{Shellwords.escape(dir)} --force 2>/dev/null || true)") shell.run!( <<~TXT cd #{repo_path} && \ git worktree add \ -B #{Shellwords.escape(branch)} \ #{Shellwords.escape(dir)} \ #{Shellwords.escape(revision)} TXT ) end |
#diff ⇒ Object
33 34 35 |
# File 'lib/agent_c/utils/git.rb', line 33 def diff shell.run!("cd #{repo_path} && git diff") end |
#fixup_commit(revision) ⇒ Object
46 47 48 49 |
# File 'lib/agent_c/utils/git.rb', line 46 def fixup_commit(revision) shell.run!("cd #{repo_path} && git add --all && git commit --no-gpg-sign --fixup #{revision}") last_revision end |
#last_revision ⇒ Object
37 38 39 |
# File 'lib/agent_c/utils/git.rb', line 37 def last_revision shell.run!("cd #{repo_path} && git rev-parse @").strip end |
#reset_hard_all ⇒ Object
51 52 53 |
# File 'lib/agent_c/utils/git.rb', line 51 def reset_hard_all shell.run!("cd #{repo_path} && git add --all && git reset --hard") end |
#uncommitted_changes? ⇒ Boolean
59 60 61 62 63 64 |
# File 'lib/agent_c/utils/git.rb', line 59 def uncommitted_changes? # Check for any changes including untracked files # Returns true if there are uncommitted changes (staged, unstaged, or untracked) status = shell.run!("cd #{repo_path} && git status --porcelain") !status.strip.empty? end |