Skip to content

Commit f75e0ec

Browse files
committed
chore: rename working tree to worktree
1 parent 918487c commit f75e0ec

File tree

9 files changed

+160
-160
lines changed

9 files changed

+160
-160
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interactions easier. To accomplish this, it ties each action you can do with `gi
2626
the type of object that action operates on.
2727

2828
There are three main objects in RubyGit:
29-
* [WorkingTree](lib/ruby_git/working_tree.rb): The directory tree of actual checked
29+
* [Worktree](lib/ruby_git/worktree.rb): The directory tree of actual checked
3030
out files. The working tree normally contains the contents of the HEAD commit’s
3131
tree, plus any local changes that you have made but not yet committed.
3232
* [Index](lib/ruby_git/index.rb): The index is used as a staging area between your
@@ -67,24 +67,24 @@ RubyGit.git.path #=> '/usr/local/bin/git'
6767
RubyGit.git.version #=> [2,28,0]
6868
```
6969

70-
To work with an existing WorkingTree:
70+
To work with an existing Worktree:
7171

7272
```Ruby
73-
working_tree = RubyGit.open(working_tree_path)
74-
working_tree.append_to_file('README.md', 'New line in README.md')
75-
working_tree.add('README.md')
76-
working_tree.commit('Add a line to the README.md')
77-
working_tree.push
73+
worktree = RubyGit.open(worktree_path)
74+
worktree.append_to_file('README.md', 'New line in README.md')
75+
worktree.add('README.md')
76+
worktree.commit('Add a line to the README.md')
77+
worktree.push
7878
```
7979

80-
To create a new WorkingTree:
80+
To create a new Worktree:
8181

8282
```Ruby
83-
working_tree = RubyGit.init(working_tree_path)
84-
working_tree.write_to_file('README.md', '# My New Project')
85-
working_tree.add('README.md')
86-
working_tree.repository.add_remote(remote_name: 'origin', url: 'https://github.com/jcouball/test', default_branch: 'main')
87-
working_tree.push(remote_name: 'origin')
83+
worktree = RubyGit.init(worktree_path)
84+
worktree.write_to_file('README.md', '# My New Project')
85+
worktree.add('README.md')
86+
worktree.repository.add_remote(remote_name: 'origin', url: 'https://github.com/jcouball/test', default_branch: 'main')
87+
worktree.push(remote_name: 'origin')
8888
```
8989

9090
To tell what version of Git is being used:

lib/ruby_git.rb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require_relative 'ruby_git/encoding_normalizer'
55
require_relative 'ruby_git/errors'
66
require_relative 'ruby_git/version'
7-
require_relative 'ruby_git/working_tree'
7+
require_relative 'ruby_git/worktree'
88

99
require 'logger'
1010

@@ -14,7 +14,7 @@
1414
# the type of object that action operates on.
1515
#
1616
# There are three main objects in RubyGit:
17-
# * {WorkingTree}: The directory tree of actual checked
17+
# * {Worktree}: The directory tree of actual checked
1818
# out files. The working tree normally contains the contents of the HEAD commit's
1919
# tree, plus any local changes that you have made but not yet committed.
2020
# * Index: The index is used as a staging area between your
@@ -77,57 +77,57 @@ class << self
7777
# @see https://git-scm.com/docs/git-init git-init
7878
#
7979
# @example
80-
# working_tree = WorkingTree.init(working_tree_path)
80+
# worktree = Worktree.init(worktree_path)
8181
#
82-
# @param [String] working_tree_path the root path of a working_tree
82+
# @param [String] worktree_path the root path of a worktree
8383
#
84-
# @raise [RubyGit::Error] if working_tree_path is not a directory
84+
# @raise [RubyGit::Error] if worktree_path is not a directory
8585
#
86-
# @return [RubyGit::WorkingTree] the working_tree whose root is at `path`
86+
# @return [RubyGit::Worktree] the worktree whose root is at `path`
8787
#
88-
def self.init(working_tree_path)
89-
RubyGit::WorkingTree.init(working_tree_path)
88+
def self.init(worktree_path)
89+
RubyGit::Worktree.init(worktree_path)
9090
end
9191

92-
# Open an existing Git working tree that contains working_tree_path
92+
# Open an existing Git working tree that contains worktree_path
9393
#
9494
# @see https://git-scm.com/docs/git-open git-open
9595
#
9696
# @example
97-
# working_tree = WorkingTree.open(working_tree_path)
97+
# worktree = Worktree.open(worktree_path)
9898
#
99-
# @param [String] working_tree_path the root path of a working_tree
99+
# @param [String] worktree_path the root path of a worktree
100100
#
101-
# @raise [RubyGit::Error] if `working_tree_path` does not exist, is not a directory, or is not within
102-
# a Git working_tree.
101+
# @raise [RubyGit::Error] if `worktree_path` does not exist, is not a directory, or is not within
102+
# a Git worktree.
103103
#
104-
# @return [RubyGit::WorkingTree] the working_tree that contains `working_tree_path`
104+
# @return [RubyGit::Worktree] the worktree that contains `worktree_path`
105105
#
106-
def self.open(working_tree_path)
107-
RubyGit::WorkingTree.open(working_tree_path)
106+
def self.open(worktree_path)
107+
RubyGit::Worktree.open(worktree_path)
108108
end
109109

110110
# Copy the remote repository and checkout the default branch
111111
#
112112
# Clones the repository referred to by `repository_url` into a newly created
113113
# directory, creates remote-tracking branches for each branch in the cloned repository,
114-
# and checks out the default branch in the working_tree whose root directory is `to_path`.
114+
# and checks out the default branch in the worktree whose root directory is `to_path`.
115115
#
116116
# @see https://git-scm.com/docs/git-clone git-clone
117117
#
118-
# @example Using default for WorkingTree path
118+
# @example Using default for Worktree path
119119
# FileUtils.pwd
120120
# => "/Users/jsmith"
121-
# working_tree = WorkingTree.clone('https://github.com/main-branch/ruby_git.git')
122-
# working_tree.path
121+
# worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git')
122+
# worktree.path
123123
# => "/Users/jsmith/ruby_git"
124124
#
125-
# @example Using a specified working_tree_path
125+
# @example Using a specified worktree_path
126126
# FileUtils.pwd
127127
# => "/Users/jsmith"
128-
# working_tree_path = '/tmp/project'
129-
# working_tree = WorkingTree.clone('https://github.com/main-branch/ruby_git.git', to_path: working_tree_path)
130-
# working_tree.path
128+
# worktree_path = '/tmp/project'
129+
# worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git', to_path: worktree_path)
130+
# worktree.path
131131
# => "/tmp/project"
132132
#
133133
# @param [String] repository_url a reference to a Git repository
@@ -140,10 +140,10 @@ def self.open(working_tree_path)
140140
# @raise [RubyGit::Error] if (1) `repository_url` is not valid or does not point to a valid repository OR
141141
# (2) `to_path` is not an empty directory.
142142
#
143-
# @return [RubyGit::WorkingTree] the working tree checked out from the cloned repository
143+
# @return [RubyGit::Worktree] the working tree checked out from the cloned repository
144144
#
145145
def self.clone(repository_url, to_path: '')
146-
RubyGit::WorkingTree.clone(repository_url, to_path:)
146+
RubyGit::Worktree.clone(repository_url, to_path:)
147147
end
148148

149149
# The version of git referred to by the path

lib/ruby_git/command_line.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ module CommandLine
2323
#
2424
# @example A more complex example
2525
# command = %w[rev-parse --show-toplevel]
26-
# options = { chdir: working_tree_path, chomp: true, out: StringIO.new, err: StringIO.new }
26+
# options = { chdir: worktree_path, chomp: true, out: StringIO.new, err: StringIO.new }
2727
# RubyGit::CommandLine.run(*command, **options).stdout #=> "/path/to/working/tree"
2828
#
2929
# @param args [Array<String>] the git command and it arguments
3030
# @param repository_path [String] the path to the git repository
31-
# @param working_tree_path [String] the path to the working tree
31+
# @param worktree_path [String] the path to the working tree
3232
# @param options [Hash<Symbol, Object>] options to pass to the command line runner
3333
#
3434
# @return [RubyGit::CommandLine::Result] the result of running the command
@@ -39,11 +39,11 @@ module CommandLine
3939
# @raise [RubyGit::SignaledError] if the command terminates due to an uncaught signal
4040
# @raise [RubyGit::ProcessIOError] if an exception is raised while collecting subprocess output
4141
#
42-
def self.run(*args, repository_path: nil, working_tree_path: nil, **options)
42+
def self.run(*args, repository_path: nil, worktree_path: nil, **options)
4343
runner = RubyGit::CommandLine::Runner.new(
4444
env,
4545
binary_path,
46-
global_options(repository_path:, working_tree_path:),
46+
global_options(repository_path:, worktree_path:),
4747
logger
4848
)
4949
runner.call(*args, **options)
@@ -70,10 +70,10 @@ def self.binary_path = RubyGit.binary_path
7070
# The global options that will be set for all git commands
7171
# @return [Array<String>]
7272
# @api private
73-
def self.global_options(repository_path:, working_tree_path:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
73+
def self.global_options(repository_path:, worktree_path:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
7474
[].tap do |global_opts|
7575
global_opts << "--git-dir=#{repository_path}" unless repository_path.nil?
76-
global_opts << "--work-tree=#{working_tree_path}" unless working_tree_path.nil?
76+
global_opts << "--work-tree=#{worktree_path}" unless worktree_path.nil?
7777
global_opts << '-c' << 'core.quotePath=true'
7878
global_opts << '-c' << 'color.ui=false'
7979
global_opts << '-c' << 'color.advice=false'
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ module RubyGit
66
# The working tree is a directory tree consisting of the checked out files that
77
# you are currently working on.
88
#
9-
# Create a new WorkingTree using {.init}, {.clone}, or {.open}.
9+
# Create a new Worktree using {.init}, {.clone}, or {.open}.
1010
#
11-
class WorkingTree
11+
class Worktree
1212
# The root path of the working tree
1313
#
1414
# @example
15-
# working_tree_path = '/Users/James/myproject'
16-
# working_tree = WorkingTree.open(working_tree_path)
17-
# working_tree.path
15+
# worktree_path = '/Users/James/myproject'
16+
# worktree = Worktree.open(worktree_path)
17+
# worktree.path
1818
# => '/Users/James/myproject'
1919
#
20-
# @return [Pathname] the root path of the working_tree
20+
# @return [Pathname] the root path of the worktree
2121
#
2222
attr_reader :path
2323

@@ -28,40 +28,40 @@ class WorkingTree
2828
# @see https://git-scm.com/docs/git-init git-init
2929
#
3030
# @example
31-
# working_tree = WorkingTree.init(working_tree_path)
31+
# worktree = Worktree.init(worktree_path)
3232
#
33-
# @param [String] working_tree_path the root path of a Git working tree
33+
# @param [String] worktree_path the root path of a Git working tree
3434
#
35-
# @raise [RubyGit::Error] if working_tree_path is not a directory
35+
# @raise [RubyGit::Error] if worktree_path is not a directory
3636
#
37-
# @return [RubyGit::WorkingTree] the working tree whose root is at `path`
37+
# @return [RubyGit::Worktree] the working tree whose root is at `path`
3838
#
39-
def self.init(working_tree_path)
40-
raise RubyGit::Error, "Path '#{working_tree_path}' not valid." unless File.directory?(working_tree_path)
39+
def self.init(worktree_path)
40+
raise RubyGit::Error, "Path '#{worktree_path}' not valid." unless File.directory?(worktree_path)
4141

4242
command = ['init']
43-
options = { chdir: working_tree_path, out: StringIO.new, err: StringIO.new }
43+
options = { chdir: worktree_path, out: StringIO.new, err: StringIO.new }
4444
RubyGit::CommandLine.run(*command, **options)
4545

46-
new(working_tree_path)
46+
new(worktree_path)
4747
end
4848

49-
# Open an existing Git working tree that contains working_tree_path
49+
# Open an existing Git working tree that contains worktree_path
5050
#
5151
# @see https://git-scm.com/docs/git-open git-open
5252
#
5353
# @example
54-
# working_tree = WorkingTree.open(working_tree_path)
54+
# worktree = Worktree.open(worktree_path)
5555
#
56-
# @param [String] working_tree_path the root path of a Git working tree
56+
# @param [String] worktree_path the root path of a Git working tree
5757
#
58-
# @raise [RubyGit::Error] if `working_tree_path` does not exist, is not a directory, or is not within
58+
# @raise [RubyGit::Error] if `worktree_path` does not exist, is not a directory, or is not within
5959
# a Git working tree.
6060
#
61-
# @return [RubyGit::WorkingTree] the Git working tree that contains `working_tree_path`
61+
# @return [RubyGit::Worktree] the Git working tree that contains `worktree_path`
6262
#
63-
def self.open(working_tree_path)
64-
new(working_tree_path)
63+
def self.open(worktree_path)
64+
new(worktree_path)
6565
end
6666

6767
# Copy the remote repository and checkout the default branch
@@ -72,19 +72,19 @@ def self.open(working_tree_path)
7272
#
7373
# @see https://git-scm.com/docs/git-clone git-clone
7474
#
75-
# @example Using default for WorkingTree path
75+
# @example Using default for Worktree path
7676
# FileUtils.pwd
7777
# => "/Users/jsmith"
78-
# working_tree = WorkingTree.clone('https://github.com/main-branch/ruby_git.git')
79-
# working_tree.path
78+
# worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git')
79+
# worktree.path
8080
# => "/Users/jsmith/ruby_git"
8181
#
82-
# @example Using a specified working_tree_path
82+
# @example Using a specified worktree_path
8383
# FileUtils.pwd
8484
# => "/Users/jsmith"
85-
# working_tree_path = '/tmp/project'
86-
# working_tree = WorkingTree.clone('https://github.com/main-branch/ruby_git.git', to_path: working_tree_path)
87-
# working_tree.path
85+
# worktree_path = '/tmp/project'
86+
# worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git', to_path: worktree_path)
87+
# worktree.path
8888
# => "/tmp/project"
8989
#
9090
# @param [String] repository_url a reference to a Git repository
@@ -97,7 +97,7 @@ def self.open(working_tree_path)
9797
# @raise [RubyGit::FailedError] if (1) `repository_url` is not valid or does not point to a valid repository OR
9898
# (2) `to_path` is not an empty directory.
9999
#
100-
# @return [RubyGit::WorkingTree] the Git working tree checked out from the cloned repository
100+
# @return [RubyGit::Worktree] the Git working tree checked out from the cloned repository
101101
#
102102
def self.clone(repository_url, to_path: '')
103103
command = ['clone', '--', repository_url, to_path]
@@ -108,13 +108,13 @@ def self.clone(repository_url, to_path: '')
108108

109109
private
110110

111-
# Create a WorkingTree object
111+
# Create a Worktree object
112112
# @api private
113113
#
114-
def initialize(working_tree_path)
115-
raise RubyGit::Error, "Path '#{working_tree_path}' not valid." unless File.directory?(working_tree_path)
114+
def initialize(worktree_path)
115+
raise RubyGit::Error, "Path '#{worktree_path}' not valid." unless File.directory?(worktree_path)
116116

117-
@path = root_path(working_tree_path)
117+
@path = root_path(worktree_path)
118118
RubyGit.logger.debug("Created #{inspect}")
119119
end
120120

@@ -126,14 +126,14 @@ def initialize(working_tree_path)
126126
#
127127
# @api private
128128
#
129-
def root_path(working_tree_path)
129+
def root_path(worktree_path)
130130
command = %w[rev-parse --show-toplevel]
131-
options = { chdir: working_tree_path, chomp: true, out: StringIO.new, err: StringIO.new }
131+
options = { chdir: worktree_path, chomp: true, out: StringIO.new, err: StringIO.new }
132132
RubyGit::CommandLine.run(*command, **options).stdout
133133
end
134134

135135
# def run(*command, **options)
136-
# RubyGit::CommandLine.run(*command, working_tree_path: path, **options)
136+
# RubyGit::CommandLine.run(*command, worktree_path: path, **options)
137137
# end
138138
end
139139
end

0 commit comments

Comments
 (0)