Skip to content

Commit c0007e5

Browse files
committed
feat: add initial_branch option to RubyGit.init
1 parent aa39ed9 commit c0007e5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/ruby_git.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ class << self
8080
# @see https://git-scm.com/docs/git-init git-init
8181
#
8282
# @example
83-
# worktree = Worktree.init(worktree_path)
83+
# worktree = Worktree.init(worktree_path, initial_branch: 'main')
8484
#
85-
# @param [String] worktree_path the root path of a worktree
85+
# @param worktree_path [String] the root path of a worktree
86+
# @param initial_branch [String] the initial branch in the newly created repository
8687
#
8788
# @raise [RubyGit::Error] if worktree_path is not a directory
8889
#
8990
# @return [RubyGit::Worktree] the worktree whose root is at `path`
9091
#
91-
def self.init(worktree_path)
92-
RubyGit::Worktree.init(worktree_path)
92+
def self.init(worktree_path, initial_branch:)
93+
RubyGit::Worktree.init(worktree_path, initial_branch:)
9394
end
9495

9596
# Open an existing Git working tree that contains worktree_path

lib/ruby_git/worktree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Worktree
2929
# @see https://git-scm.com/docs/git-init git-init
3030
#
3131
# @example
32-
# worktree = Worktree.init(worktree_path)
32+
# worktree = Worktree.init(worktree_path, initial_branch: 'main')
3333
#
3434
# @param worktree_path [String] the root path of a Git working tree
3535
# @param initial_branch [String] the initial branch in the newly created repository

spec/lib/ruby_git_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
end
4141

4242
describe '.init' do
43+
subject { RubyGit.init(worktree_path, initial_branch:) }
4344
let(:worktree_path) { '/Users/jsmith/my_project' }
44-
subject { RubyGit.init(worktree_path) }
45+
let(:initial_branch) { 'xxx' }
4546
it 'should call RubyGit::Worktree.init with the same arguments' do
4647
worktree_class = class_double('RubyGit::Worktree')
4748
stub_const('RubyGit::Worktree', worktree_class)
48-
expect(worktree_class).to receive(:init).with(worktree_path)
49+
expect(worktree_class).to receive(:init).with(worktree_path, initial_branch:)
4950
subject
5051
end
5152
end

0 commit comments

Comments
 (0)