Class: Workbush::Worktree
- Inherits:
-
Object
- Object
- Workbush::Worktree
- Defined in:
- lib/workbush/worktree.rb
Overview
Handles git worktree operations
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.list ⇒ Array<Hash>
List all worktrees in the repository.
-
.remove(path, force: false) ⇒ Boolean
Remove a worktree.
Instance Method Summary collapse
-
#create(force: false) ⇒ String
Create the worktree.
-
#initialize(path:, branch: nil, source_path: Dir.pwd) ⇒ Worktree
constructor
Initialize a new Worktree instance.
-
#source_path ⇒ String
Get the parent/source worktree path.
Constructor Details
#initialize(path:, branch: nil, source_path: Dir.pwd) ⇒ Worktree
Initialize a new Worktree instance
17 18 19 20 21 |
# File 'lib/workbush/worktree.rb', line 17 def initialize(path:, branch: nil, source_path: Dir.pwd) @path = File.(path) @branch = branch @source_path = source_path end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
10 11 12 |
# File 'lib/workbush/worktree.rb', line 10 def branch @branch end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/workbush/worktree.rb', line 10 def path @path end |
Class Method Details
.list ⇒ Array<Hash>
List all worktrees in the repository
47 48 49 50 51 52 53 |
# File 'lib/workbush/worktree.rb', line 47 def self.list stdout, stderr, status = Open3.capture3("git", "worktree", "list", "--porcelain") raise GitError, "Failed to list worktrees: #{stderr}" unless status.success? parse_worktree_list(stdout) end |
.remove(path, force: false) ⇒ Boolean
Remove a worktree
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/workbush/worktree.rb', line 61 def self.remove(path, force: false) cmd = ["git", "worktree", "remove", path] cmd << "--force" if force stdout, stderr, status = Open3.capture3(*cmd) unless status.success? raise WorktreeError, "Failed to remove worktree: #{stderr}" end true end |
Instance Method Details
#create(force: false) ⇒ String
Create the worktree
29 30 31 32 33 34 35 |
# File 'lib/workbush/worktree.rb', line 29 def create(force: false) validate_git_repository! validate_path!(force) cmd = build_git_command(force) execute_git_command(cmd) end |
#source_path ⇒ String
Get the parent/source worktree path
40 41 42 |
# File 'lib/workbush/worktree.rb', line 40 def source_path @source_path end |