Class: RubyGit::Worktree
- Inherits:
-
Object
- Object
- RubyGit::Worktree
- Defined in:
- lib/ruby_git/worktree.rb
Overview
The Worktree is a directory tree consisting of the checked out files that you are currently working on.
Create a new Worktree using Worktree.init, Worktree.clone, or Worktree.open.
Instance Attribute Summary collapse
-
#path ⇒ Pathname
readonly
The root path of the worktree.
Class Method Summary collapse
-
.clone(repository_url, to_path: '') ⇒ RubyGit::Worktree
Copy the remote repository and checkout the default branch.
-
.init(worktree_path) ⇒ RubyGit::Worktree
Create an empty Git repository under the root worktree
path
. -
.open(worktree_path) ⇒ RubyGit::Worktree
Open an existing Git worktree that contains worktree_path.
Instance Attribute Details
#path ⇒ Pathname (readonly)
The root path of the worktree
22 23 24 |
# File 'lib/ruby_git/worktree.rb', line 22 def path @path end |
Class Method Details
.clone(repository_url, to_path: '') ⇒ RubyGit::Worktree
Copy the remote repository and checkout the default branch
Clones the repository referred to by repository_url
into a newly created
directory, creates remote-tracking branches for each branch in the cloned repository,
and checks out the default branch in the worktree whose root directory is to_path
.
to_path
will be created if it does not exist. An error is raised if to_path
exists and
not an empty directory.
101 102 103 104 105 106 107 |
# File 'lib/ruby_git/worktree.rb', line 101 def self.clone(repository_url, to_path: '') command = [RubyGit.git.path.to_s, 'clone', '--', repository_url, to_path] _out, err, status = Open3.capture3(*command) raise RubyGit::Error, err unless status.success? new(to_path) end |
.init(worktree_path) ⇒ RubyGit::Worktree
Create an empty Git repository under the root worktree path
If the repository already exists, it will not be overwritten.
39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_git/worktree.rb', line 39 def self.init(worktree_path) raise RubyGit::Error, "Path '#{worktree_path}' not valid." unless File.directory?(worktree_path) command = [RubyGit.git.path.to_s, 'init'] _out, err, status = Open3.capture3(*command, chdir: worktree_path) raise RubyGit::Error, err unless status.success? Worktree.new(worktree_path) end |
.open(worktree_path) ⇒ RubyGit::Worktree
Open an existing Git worktree that contains worktree_path
62 63 64 |
# File 'lib/ruby_git/worktree.rb', line 62 def self.open(worktree_path) new(worktree_path) end |